11import assert from "node:assert"
2- import moment from "moment" ;
32import { testContext , disposeTestDocumentStore } from "../Utils/TestUtil.js" ;
43
54import {
@@ -9,10 +8,7 @@ import {
98import { DateUtil } from "../../src/Utility/DateUtil.js" ;
109import { StringUtil } from "../../src/Utility/StringUtil.js" ;
1110import { assertThat } from "../Utils/AssertExtensions.js" ;
12-
13-
14- const momentDefaultDateFormat = "YYYY-MM-DDTHH:mm:ss.SSS0000" ;
15- const momentDefaultDateTzFormat = "YYYY-MM-DDTHH:mm:ss.SSS0000Z" ;
11+ import { format } from "date-fns" ;
1612
1713// getTimezoneOffset() returns reversed offset, hence the "-"
1814const LOCAL_TIMEZONE_OFFSET = - ( new Date ( 2018 , 7 , 1 ) . getTimezoneOffset ( ) ) ;
@@ -141,7 +137,7 @@ describe("DateUtil", function () {
141137 const dateUtil = new DateUtil ( {
142138 withTimezone : false
143139 } ) ;
144- const date = moment ( "2018-10-15T09:46:28.306" ) . toDate ( ) ;
140+ const date = DateUtil . default . parse ( "2018-10-15T09:46:28.306" ) ;
145141 const stringified = dateUtil . stringify ( date ) ;
146142 assert . strictEqual ( stringified , "2018-10-15T09:46:28.3060000" ) ;
147143
@@ -155,11 +151,11 @@ describe("DateUtil", function () {
155151 withTimezone : false ,
156152 useUtcDates : true
157153 } ) ;
158- const date = moment ( "2018-10-15T12:00:00.000" ) . toDate ( ) ;
154+ const date = DateUtil . default . parse ( "2018-10-15T12:00:00.000" ) ;
159155 const stringified = dateUtil . stringify ( date ) ;
160156
161157 const expected = new Date ( 2018 , 9 , 15 , date . getHours ( ) - LOCAL_TIMEZONE_OFFSET_HOURS , 0 , 0 , 0 ) ;
162- const expectedStringified = moment ( expected ) . format ( momentDefaultDateFormat ) + "Z" ;
158+ const expectedStringified = format ( expected , DateUtil . DEFAULT_DATE_FORMAT ) + "Z" ;
163159 assert . strictEqual ( stringified , expectedStringified ) ;
164160
165161 const parsed = dateUtil . parse ( stringified ) ;
@@ -178,15 +174,14 @@ describe("DateUtil", function () {
178174
179175 const hour6 = 12 ;
180176 const timezoneOffsetHours = 6 ;
181- const date = moment . parseZone ( `2018-10-15T${ hour6 } :00:00.0000000+06:00` ) . toDate ( ) ;
177+ const date = DateUtil . tz . parse ( `2018-10-15T${ hour6 } :00:00.0000000+06:00` ) ;
182178 // preconditions check
183179 assert . strictEqual (
184180 date . getHours ( ) , hour6 - timezoneOffsetHours + LOCAL_TIMEZONE_OFFSET_HOURS ) ;
185181
186182 const expectedHours = date . getHours ( ) ;
187183 const expected = new Date ( 2018 , 9 , 15 , expectedHours , 0 , 0 , 0 ) ;
188- const expectedStringified =
189- moment ( expected ) . format ( momentDefaultDateFormat ) + LOCAL_TIMEZONE_STRING ;
184+ const expectedStringified = format ( expected , DateUtil . DEFAULT_DATE_FORMAT ) + LOCAL_TIMEZONE_STRING ;
190185 const stringified = dateUtil . stringify ( date ) ;
191186 assert . strictEqual ( stringified , expectedStringified ) ;
192187
@@ -203,16 +198,15 @@ describe("DateUtil", function () {
203198
204199 const hour6 = 12 ;
205200 const timezoneOffsetHours = 6 ;
206- const date = moment . parseZone ( `2018-10-15T${ hour6 } :00:00.0000000+06:00` ) . toDate ( ) ;
201+ const date = DateUtil . tz . parse ( `2018-10-15T${ hour6 } :00:00.0000000+06:00` ) ;
207202 // preconditions check
208203 assert . strictEqual (
209204 date . getHours ( ) , hour6 - timezoneOffsetHours + LOCAL_TIMEZONE_OFFSET_HOURS ) ;
210205
211206 const expectedHours = date . getHours ( ) - LOCAL_TIMEZONE_OFFSET_HOURS ;
212207 const utcTimezoneString = "+00:00" ;
213208 const expected = new Date ( 2018 , 9 , 15 , expectedHours , 0 , 0 , 0 ) ;
214- const expectedStringified =
215- moment ( expected ) . format ( momentDefaultDateFormat ) + utcTimezoneString ;
209+ const expectedStringified = format ( expected , DateUtil . DEFAULT_DATE_FORMAT ) + utcTimezoneString ;
216210 const stringified = dateUtil . stringify ( date ) ;
217211 assert . strictEqual ( stringified , expectedStringified ) ;
218212
0 commit comments