Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/modules/Date.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Added in v2.0.0
- [instances](#instances)
- [Eq](#eq)
- [Ord](#ord)
- [Show](#show)
- [eqDate](#eqdate)
- [eqMonth](#eqmonth)
- [eqYear](#eqyear)
Expand Down Expand Up @@ -69,6 +70,24 @@ assert.deepStrictEqual(Ord.compare(new Date(1, 1, 2020), new Date(1, 1, 2021)),

Added in v2.10.0

## Show

**Signature**

```ts
export declare const Show: Sh.Show<Date>
```

**Example**

```ts
import { Show } from 'fp-ts/Date'

assert.deepStrictEqual(Show.show(new Date(2020, 0, 1)), '2020-01-01T00:00:00.000Z')
```

Added in v2.11.9

## eqDate

**Signature**
Expand Down
14 changes: 14 additions & 0 deletions src/Date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { pipe } from './function'
import { IO } from './IO'
import * as O from './Ord'
import * as N from './number'
import * as Sh from './Show'

// -------------------------------------------------------------------------------------
// instances
Expand Down Expand Up @@ -60,6 +61,19 @@ export const Ord: O.Ord<Date> =
O.contramap((date) => date.valueOf())
)

/**
* @example
* import { Show } from 'fp-ts/Date'
*
* assert.deepStrictEqual(Show.show(new Date(2020, 0, 1)), '2020-01-01T00:00:00.000Z')
*
* @category instances
* @since 2.11.9
*/
export const Show: Sh.Show<Date> = {
show: (a) => a.toISOString()
}

// -------------------------------------------------------------------------------------
// utils
// -------------------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions test/Date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ describe('Date', () => {
U.deepStrictEqual(_.Ord.compare(new Date(1), new Date(0)), 1)
})

it('Show', () => {
U.deepStrictEqual(_.Show.show(new Date(0)), '1970-01-01T00:00:00.000Z')
})

// -------------------------------------------------------------------------------------
// utils
// -------------------------------------------------------------------------------------
Expand Down