@@ -10,19 +10,17 @@ import {
1010import { Meridiem } from "../types" ;
1111
1212export function now ( reference : ReferenceWithTimezone ) : ParsingComponents {
13- const targetDate = dayjs ( reference . instant ) ;
13+ const targetDate = dayjs ( reference . getDateWithAdjustedTimezone ( ) ) ;
1414 const component = new ParsingComponents ( reference , { } ) ;
1515 assignSimilarDate ( component , targetDate ) ;
1616 assignSimilarTime ( component , targetDate ) ;
17- if ( reference . timezoneOffset !== null ) {
18- component . assign ( "timezoneOffset" , targetDate . utcOffset ( ) ) ;
19- }
17+ component . assign ( "timezoneOffset" , reference . getTimezoneOffset ( ) ) ;
2018 component . addTag ( "casualReference/now" ) ;
2119 return component ;
2220}
2321
2422export function today ( reference : ReferenceWithTimezone ) : ParsingComponents {
25- const targetDate = dayjs ( reference . instant ) ;
23+ const targetDate = dayjs ( reference . getDateWithAdjustedTimezone ( ) ) ;
2624 const component = new ParsingComponents ( reference , { } ) ;
2725 assignSimilarDate ( component , targetDate ) ;
2826 implySimilarTime ( component , targetDate ) ;
@@ -49,7 +47,7 @@ export function tomorrow(reference: ReferenceWithTimezone): ParsingComponents {
4947}
5048
5149export function theDayAfter ( reference : ReferenceWithTimezone , nDays : number ) : ParsingComponents {
52- let targetDate = dayjs ( reference . instant ) ;
50+ let targetDate = dayjs ( reference . getDateWithAdjustedTimezone ( ) ) ;
5351 const component = new ParsingComponents ( reference , { } ) ;
5452 targetDate = targetDate . add ( nDays , "day" ) ;
5553 assignSimilarDate ( component , targetDate ) ;
@@ -58,7 +56,7 @@ export function theDayAfter(reference: ReferenceWithTimezone, nDays: number): Pa
5856}
5957
6058export function tonight ( reference : ReferenceWithTimezone , implyHour = 22 ) : ParsingComponents {
61- const targetDate = dayjs ( reference . instant ) ;
59+ const targetDate = dayjs ( reference . getDateWithAdjustedTimezone ( ) ) ;
6260 const component = new ParsingComponents ( reference , { } ) ;
6361 assignSimilarDate ( component , targetDate ) ;
6462 component . imply ( "hour" , implyHour ) ;
@@ -68,7 +66,7 @@ export function tonight(reference: ReferenceWithTimezone, implyHour = 22): Parsi
6866}
6967
7068export function lastNight ( reference : ReferenceWithTimezone , implyHour = 0 ) : ParsingComponents {
71- let targetDate = dayjs ( reference . instant ) ;
69+ let targetDate = dayjs ( reference . getDateWithAdjustedTimezone ( ) ) ;
7270 const component = new ParsingComponents ( reference , { } ) ;
7371 if ( targetDate . hour ( ) < 6 ) {
7472 targetDate = targetDate . add ( - 1 , "day" ) ;
@@ -87,7 +85,7 @@ export function evening(reference: ReferenceWithTimezone, implyHour = 20): Parsi
8785}
8886
8987export function yesterdayEvening ( reference : ReferenceWithTimezone , implyHour = 20 ) : ParsingComponents {
90- let targetDate = dayjs ( reference . instant ) ;
88+ let targetDate = dayjs ( reference . getDateWithAdjustedTimezone ( ) ) ;
9189 const component = new ParsingComponents ( reference , { } ) ;
9290 targetDate = targetDate . add ( - 1 , "day" ) ;
9391 assignSimilarDate ( component , targetDate ) ;
@@ -100,7 +98,7 @@ export function yesterdayEvening(reference: ReferenceWithTimezone, implyHour = 2
10098
10199export function midnight ( reference : ReferenceWithTimezone ) : ParsingComponents {
102100 const component = new ParsingComponents ( reference , { } ) ;
103- const targetDate = dayjs ( reference . instant ) ;
101+ const targetDate = dayjs ( reference . getDateWithAdjustedTimezone ( ) ) ;
104102 if ( targetDate . hour ( ) > 2 ) {
105103 // Unless it's very early morning (0~2AM), we assume the midnight is the coming midnight.
106104 // Thus, increasing the day by 1.
0 commit comments