From c2ddeb4180a19069d769ce4d88e3980af4893afc Mon Sep 17 00:00:00 2001 From: "Mr.Dr.Professor Patrick" Date: Fri, 20 Jan 2023 13:24:54 +0100 Subject: [PATCH] fix: fix DateTime interface (#9) --- src/dateTime/dateTime.test.ts | 13 +++++++++++++ src/typings/dateTime.ts | 23 ++++++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/dateTime/dateTime.test.ts b/src/dateTime/dateTime.test.ts index a14793f..5876010 100644 --- a/src/dateTime/dateTime.test.ts +++ b/src/dateTime/dateTime.test.ts @@ -61,5 +61,18 @@ describe('DateTime', () => { .format(DEFAULT_SYSTEM_DATE_FORMAT); expect(date).toEqual('2021-08-01'); }); + + it('should set/get hours, minutes, seconds, millisecond', () => { + let date = dateTime({input: TESTED_DATE_STRING}); + expect(date.millisecond()).toEqual(0); + expect(date.second()).toEqual(0); + expect(date.minute()).toEqual(0); + expect(date.hour()).toEqual(0); + date = date.hour(10).minute(10).second(10).millisecond(999); + expect(date.millisecond()).toEqual(999); + expect(date.second()).toEqual(10); + expect(date.minute()).toEqual(10); + expect(date.hour()).toEqual(10); + }); }); }); diff --git a/src/typings/dateTime.ts b/src/typings/dateTime.ts index a99ef9d..f0d51d4 100644 --- a/src/typings/dateTime.ts +++ b/src/typings/dateTime.ts @@ -63,11 +63,20 @@ export interface DateTime extends Object { utc: () => DateTime; utcOffset: () => number; daysInMonth: () => number; - date: () => number; - month: () => number; - year: () => number; - day: () => number; - hour: () => number; - minute: () => number; - second: () => number; + date(): number; + date(value: number): DateTime; + month(): number; + month(value: number): DateTime; + year(): number; + year(value: number): DateTime; + day(): number; + day(value: number): DateTime; + hour(): number; + hour(value: number): DateTime; + minute(): number; + minute(value: number): DateTime; + second(): number; + second(value: number): DateTime; + millisecond(): number; + millisecond(value: number): DateTime; }