diff --git a/docs/modules/Date.ts.md b/docs/modules/Date.ts.md index d2dbd5111..1943d1bbf 100644 --- a/docs/modules/Date.ts.md +++ b/docs/modules/Date.ts.md @@ -17,6 +17,7 @@ Added in v2.0.0 - [instances](#instances) - [Eq](#eq) - [Ord](#ord) + - [Show](#show) - [eqDate](#eqdate) - [eqMonth](#eqmonth) - [eqYear](#eqyear) @@ -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 +``` + +**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** diff --git a/src/Date.ts b/src/Date.ts index 95dfb449e..3d58276af 100644 --- a/src/Date.ts +++ b/src/Date.ts @@ -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 @@ -60,6 +61,19 @@ export const Ord: O.Ord = 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 = { + show: (a) => a.toISOString() +} + // ------------------------------------------------------------------------------------- // utils // ------------------------------------------------------------------------------------- diff --git a/test/Date.ts b/test/Date.ts index 9896108b9..d9722b827 100644 --- a/test/Date.ts +++ b/test/Date.ts @@ -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 // -------------------------------------------------------------------------------------