Skip to content

Commit

Permalink
Document formatDate
Browse files Browse the repository at this point in the history
  • Loading branch information
colincasey committed Apr 12, 2024
1 parent 96da5c8 commit 9b64223
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ docs/*.md

# subsequent PRs will un-ignore areas that are under review until
# all docs are complete and we can drop this ignore file entirely
!docs/tough-cookie.formatdate.md
!docs/tough-cookie.domainmatch.md
!docs/tough-cookie.defaultpath.md
!docs/tough-cookie.cookiecompare.md
Expand Down
60 changes: 60 additions & 0 deletions api/docs/tough-cookie.formatdate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [tough-cookie](./tough-cookie.md) &gt; [formatDate](./tough-cookie.formatdate.md)

## formatDate() function

Format a [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) into the [preferred Internet standard format](https://www.rfc-editor.org/rfc/rfc2616#section-3.3.1) defined in [RFC822](https://www.rfc-editor.org/rfc/rfc822#section-5) and updated in [RFC1123](https://www.rfc-editor.org/rfc/rfc1123#page-55)<!-- -->.

**Signature:**

```typescript
export declare function formatDate(date: Date): string;
```

## Parameters

<table><thead><tr><th>

Parameter


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

date


</td><td>

Date


</td><td>

the date value to format


</td></tr>
</tbody></table>
**Returns:**

string

## Example


```
formatDate(new Date(0)) === 'Thu, 01 Jan 1970 00:00:00 GMT`
```

15 changes: 14 additions & 1 deletion lib/cookie/formatDate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import * as validators from '../validators'
import { safeToString } from '../utils'

/** Converts a Date to a UTC string representation. */
/**
* Format a {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date | Date} into
* the {@link https://www.rfc-editor.org/rfc/rfc2616#section-3.3.1 | preferred Internet standard format}
* defined in {@link https://www.rfc-editor.org/rfc/rfc822#section-5 | RFC822} and
* updated in {@link https://www.rfc-editor.org/rfc/rfc1123#page-55 | RFC1123}.
*
* @example
* ```
* formatDate(new Date(0)) === 'Thu, 01 Jan 1970 00:00:00 GMT`
* ```
*
* @param date - the date value to format
* @public
*/
export function formatDate(date: Date): string {
validators.validate(validators.isDate(date), safeToString(date))
return date.toUTCString()
Expand Down

0 comments on commit 9b64223

Please sign in to comment.