1
1
import * as chrono from "../../src" ;
2
2
import { testSingleCase } from "../test_util" ;
3
3
4
- test ( "Test - Parsing date with UTC offset" , function ( ) {
4
+ test ( "Test - Parsing date/time with UTC offset" , function ( ) {
5
5
testSingleCase ( chrono , "wednesday, september 16, 2020 at 11 am utc+02:45 " , ( result , text ) => {
6
6
expect ( result . text ) . toBe ( "wednesday, september 16, 2020 at 11 am utc+02:45" ) ;
7
7
@@ -27,7 +27,7 @@ test("Test - Parsing date with UTC offset", function () {
27
27
} ) ;
28
28
} ) ;
29
29
30
- test ( "Test - Parsing date with GMT offset" , function ( ) {
30
+ test ( "Test - Parsing date/time with GMT offset" , function ( ) {
31
31
testSingleCase ( chrono , "wednesday, september 16, 2020 at 11 am GMT -08:45 " , ( result , text ) => {
32
32
expect ( result . text ) . toBe ( "wednesday, september 16, 2020 at 11 am GMT -08:45" ) ;
33
33
@@ -45,7 +45,7 @@ test("Test - Parsing date with GMT offset", function () {
45
45
} ) ;
46
46
} ) ;
47
47
48
- test ( "Test - Parsing date with timezone abbreviation" , function ( ) {
48
+ test ( "Test - Parsing date/time with timezone abbreviation" , function ( ) {
49
49
testSingleCase ( chrono , "wednesday, september 16, 2020 at 11 am" , ( result , text ) => {
50
50
expect ( result . text ) . toBe ( text ) ;
51
51
@@ -73,21 +73,47 @@ test("Test - Parsing date with timezone abbreviation", function () {
73
73
} ) ;
74
74
} ) ;
75
75
76
- test ( "Test - Not parsing timezone from relative date" , function ( ) {
76
+ test ( "Test - Parsing date with timezone abbreviation" , function ( ) {
77
+ testSingleCase ( chrono , "Wednesday, September 16, 2020, EST" , ( result , text ) => {
78
+ expect ( result . text ) . toBe ( text ) ;
79
+ expect ( result . start . get ( "timezoneOffset" ) ) . toBe ( - 300 ) ;
80
+ } ) ;
81
+ } ) ;
82
+
83
+ test ( "Test - Not parsing timezone from relative time" , function ( ) {
77
84
const refDate = new Date ( 2020 , 11 - 1 , 14 , 13 , 48 , 22 ) ;
78
85
79
86
testSingleCase ( chrono , "in 1 hour get eggs and milk" , refDate , ( result , text ) => {
80
87
expect ( result . text ) . toBe ( "in 1 hour" ) ;
81
88
expect ( result . start . get ( "timezoneOffset" ) ) . toBe ( - refDate . getTimezoneOffset ( ) ) ;
82
89
} ) ;
83
90
84
- // testSingleCase(chrono, "in 1 hour GMT", refDate, (result, text) => {
85
- // expect(result.text).toBe("in 1 hour");
86
- // expect(result.start.get("timezoneOffset")).toBe(-refDate.getTimezoneOffset());
87
- // });
91
+ testSingleCase ( chrono , "in 3 hours GMT" , refDate , ( result , text ) => {
92
+ expect ( result . text ) . toBe ( "in 3 hours" ) ;
93
+ expect ( result . start . get ( "timezoneOffset" ) ) . toBe ( - refDate . getTimezoneOffset ( ) ) ;
94
+ } ) ;
95
+ } ) ;
96
+
97
+ test ( "Test - Parsing timezone from relative date when valid" , function ( ) {
98
+ const refDate = new Date ( 2020 , 11 - 1 , 14 , 13 , 48 , 22 ) ;
88
99
89
100
testSingleCase ( chrono , "in 1 day get eggs and milk" , refDate , ( result , text ) => {
90
101
expect ( result . text ) . toBe ( "in 1 day" ) ;
91
102
expect ( result . start . get ( "timezoneOffset" ) ) . toBe ( - refDate . getTimezoneOffset ( ) ) ;
92
103
} ) ;
104
+
105
+ testSingleCase ( chrono , "in 1 day GET" , refDate , ( result , text ) => {
106
+ expect ( result . text ) . toBe ( "in 1 day GET" ) ;
107
+ expect ( result . start . get ( "timezoneOffset" ) ) . toBe ( 240 ) ;
108
+ } ) ;
109
+
110
+ testSingleCase ( chrono , "today EST" , ( result , text ) => {
111
+ expect ( result . text ) . toBe ( text ) ;
112
+ expect ( result . start . get ( "timezoneOffset" ) ) . toBe ( - 300 ) ;
113
+ } ) ;
114
+
115
+ testSingleCase ( chrono , "next week EST" , ( result , text ) => {
116
+ expect ( result . text ) . toBe ( text ) ;
117
+ expect ( result . start . get ( "timezoneOffset" ) ) . toBe ( - 300 ) ;
118
+ } ) ;
93
119
} ) ;
0 commit comments