@@ -4,6 +4,7 @@ import dayjsGenerateConfig from '../src/generate/dayjs';
44import dayjs from 'dayjs' ;
55import utc from 'dayjs/plugin/utc' ;
66import timezone from 'dayjs/plugin/timezone' ;
7+ import moment from 'moment-timezone' ;
78
89dayjs . extend ( utc ) ;
910dayjs . extend ( timezone ) ;
@@ -12,7 +13,7 @@ const CN = 'Asia/Shanghai';
1213const JP = 'Asia/Tokyo' ;
1314
1415beforeEach ( ( ) => {
15- MockDate . set ( dayjs . tz ( '2024-09-23 05:02:03.172' , CN ) . toDate ( ) ) ;
16+ MockDate . set ( new Date ( ) ) ;
1617} ) ;
1718
1819afterEach ( ( ) => {
@@ -22,16 +23,18 @@ afterEach(() => {
2223
2324describe ( 'dayjs: getNow' , ( ) => {
2425 it ( 'normal' , ( ) => {
25- const now = new Date ( ) ;
26- expect ( now . toDateString ( ) ) . toEqual ( 'Mon Sep 23 2024' ) ;
27- expect ( now . toTimeString ( ) ) . toContain ( '05:02:03 GMT+0800' ) ;
26+ const D_now = dayjsGenerateConfig . getNow ( ) ;
27+ const M_now = moment ( ) ;
28+
29+ expect ( D_now . format ( ) ) . toEqual ( M_now . format ( ) ) ;
2830 } ) ;
2931
30- it ( 'should be work' , async ( ) => {
32+ it ( 'should work normally in timezone ' , async ( ) => {
3133 dayjs . tz . setDefault ( JP ) ;
32- const now = dayjsGenerateConfig . getNow ( ) ;
33- const L_now = dayjs ( ) ;
34- expect ( L_now . format ( ) ) . toEqual ( '2024-09-23T05:02:03+08:00' ) ;
35- expect ( now . format ( ) ) . toEqual ( '2024-09-23T06:02:03+09:00' ) ;
34+ const D_now = dayjsGenerateConfig . getNow ( ) ;
35+ const M_now = moment ( ) . tz ( JP ) ;
36+
37+ expect ( D_now . format ( ) ) . toEqual ( M_now . format ( ) ) ;
38+ expect ( D_now . get ( 'hour' ) - D_now . utc ( ) . get ( 'hour' ) ) . toEqual ( 9 ) ;
3639 } ) ;
3740} ) ;
0 commit comments