@@ -5,7 +5,8 @@ import { isValid, parseISO } from "date-fns";
5
5
6
6
import {
7
7
formatDate ,
8
- formatDateToLocal ,
8
+ formatZonedToLocalDate ,
9
+ formatLocalToZonedDate ,
9
10
getDate ,
10
11
getTimeZoneDesignator ,
11
12
getTimeZoneOffset ,
@@ -36,19 +37,32 @@ describe("util/lib/date", () => {
36
37
assert . equal ( result , now ) ;
37
38
} ) ;
38
39
39
- it ( "Formats a date as local date" , ( ) => {
40
- const tz1 = formatDateToLocal ( "2019-11-30T12:30:00+01:00" , "Asia/Taipei" ) ;
41
- const tz2 = formatDateToLocal (
40
+ it ( "Formats zoned date as local date" , ( ) => {
41
+ const tz1 = formatZonedToLocalDate (
42
+ "2019-11-30T12:30:00+01:00" ,
43
+ "Asia/Taipei" ,
44
+ ) ;
45
+ const tz2 = formatZonedToLocalDate (
42
46
"2019-11-30T12:30:00+01:00" ,
43
47
"America/Panama" ,
44
48
) ;
45
- const utc = formatDateToLocal ( "2019-11-30T12:30:00+01:00" , "UTC" ) ;
49
+ const utc = formatZonedToLocalDate ( "2019-11-30T12:30:00+01:00" , "UTC" ) ;
46
50
47
51
assert . equal ( tz1 , "2019-11-30T19:30" ) ;
48
52
assert . equal ( tz2 , "2019-11-30T06:30" ) ;
49
53
assert . equal ( utc , "2019-11-30T11:30" ) ;
50
54
} ) ;
51
55
56
+ it ( "Formats local date to zoned date" , ( ) => {
57
+ const tz1 = formatLocalToZonedDate ( "2019-11-30T12:30:00" , "Asia/Taipei" ) ;
58
+ const tz2 = formatLocalToZonedDate ( "2019-11-30T12:30:00" , "America/Panama" ) ;
59
+ const utc = formatLocalToZonedDate ( "2019-11-30T12:30:00" , "UTC" ) ;
60
+
61
+ assert . equal ( tz1 , "2019-11-30T12:30:00+08:00" ) ;
62
+ assert . equal ( tz2 , "2019-11-30T12:30:00-05:00" ) ;
63
+ assert . equal ( utc , "2019-11-30T12:30:00Z" ) ;
64
+ } ) ;
65
+
52
66
it ( "Creates UTC datetime from `client`" , ( ) => {
53
67
const result = getDate ( "client" ) ;
54
68
0 commit comments