@@ -36,7 +36,6 @@ import Onyx from 'react-native-onyx';
3636import type { ValueOf } from 'type-fest' ;
3737import type { LocaleContextProps } from '@components/LocaleContextProvider' ;
3838import CONST from '@src/CONST' ;
39- import IntlStore from '@src/languages/IntlStore' ;
4039import ONYXKEYS from '@src/ONYXKEYS' ;
4140import { timezoneBackwardToNewMap , timezoneNewToBackwardMap } from '@src/TIMEZONES' ;
4241import type Locale from '@src/types/onyx/Locale' ;
@@ -51,37 +50,6 @@ type CustomStatusTypes = ValueOf<typeof CONST.CUSTOM_STATUS_TYPES>;
5150type WeekDay = 0 | 1 | 2 | 3 | 4 | 5 | 6 ;
5251
5352const TIMEZONE_UPDATE_THROTTLE_MINUTES = 5 ;
54-
55- let currentUserAccountID : number | undefined ;
56- Onyx . connect ( {
57- key : ONYXKEYS . SESSION ,
58- callback : ( val ) => {
59- // When signed out, val is undefined
60- if ( ! val ) {
61- return ;
62- }
63-
64- currentUserAccountID = val . accountID ;
65- } ,
66- } ) ;
67-
68- let timezone : Required < Timezone > = CONST . DEFAULT_TIME_ZONE ;
69- Onyx . connect ( {
70- key : ONYXKEYS . PERSONAL_DETAILS_LIST ,
71- callback : ( value ) => {
72- if ( ! currentUserAccountID ) {
73- return ;
74- }
75-
76- const personalDetailsTimezone = value ?. [ currentUserAccountID ] ?. timezone ;
77-
78- timezone = {
79- selected : personalDetailsTimezone ?. selected ?? CONST . DEFAULT_TIME_ZONE . selected ,
80- automatic : personalDetailsTimezone ?. automatic ?? CONST . DEFAULT_TIME_ZONE . automatic ,
81- } ;
82- } ,
83- } ) ;
84-
8553let networkTimeSkew = 0 ;
8654let isOffline : boolean | undefined ;
8755
@@ -90,12 +58,12 @@ Onyx.connect({
9058 callback : ( val ) => {
9159 networkTimeSkew = val ?. timeSkew ?? 0 ;
9260 if ( ! val ?. lastOfflineAt ) {
93- setNetworkLastOffline ( getLocalDateFromDatetime ( IntlStore . getCurrentLocale ( ) ) ) ;
61+ setNetworkLastOffline ( new Date ( ) . toISOString ( ) ) ;
9462 }
9563
9664 const newIsOffline = val ?. isOffline ?? val ?. shouldForceOffline ;
9765 if ( newIsOffline && isOffline === false ) {
98- setNetworkLastOffline ( getLocalDateFromDatetime ( IntlStore . getCurrentLocale ( ) ) ) ;
66+ setNetworkLastOffline ( new Date ( ) . toISOString ( ) ) ;
9967 }
10068 isOffline = newIsOffline ;
10169 } ,
@@ -126,7 +94,7 @@ function getWeekEndsOn(): WeekDay {
12694 * Date object for the given ISO-formatted datetime string
12795 */
12896// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
129- function getLocalDateFromDatetime ( locale : Locale | undefined , datetime ?: string , currentSelectedTimezone : string | SelectedTimezone = timezone . selected ) : Date {
97+ function getLocalDateFromDatetime ( locale : Locale | undefined , currentSelectedTimezone : string | SelectedTimezone , datetime ?: string ) : Date {
13098 if ( ! datetime ) {
13199 const res = toZonedTime ( new Date ( ) , currentSelectedTimezone ) ;
132100 if ( Number . isNaN ( res . getTime ( ) ) ) {
@@ -216,14 +184,8 @@ const fallbackToSupportedTimezone = memoize((timezoneInput: SelectedTimezone): S
216184 * Jan 20 at 5:30 PM within the past year
217185 * Jan 20, 2019 at 5:30 PM anything over 1 year ago
218186 */
219- function datetimeToCalendarTime (
220- locale : Locale | undefined ,
221- datetime : string ,
222- includeTimeZone = false ,
223- currentSelectedTimezone : SelectedTimezone = timezone . selected ,
224- isLowercase = false ,
225- ) : string {
226- const date = getLocalDateFromDatetime ( locale , datetime , fallbackToSupportedTimezone ( currentSelectedTimezone ) ) ;
187+ function datetimeToCalendarTime ( locale : Locale | undefined , datetime : string , currentSelectedTimezone : SelectedTimezone , includeTimeZone = false , isLowercase = false ) : string {
188+ const date = getLocalDateFromDatetime ( locale , fallbackToSupportedTimezone ( currentSelectedTimezone ) , datetime ) ;
227189 const tz = includeTimeZone ? ' [UTC]Z' : '' ;
228190 let todayAt = translate ( locale , 'common.todayAt' ) ;
229191 let tomorrowAt = translate ( locale , 'common.tomorrowAt' ) ;
@@ -268,9 +230,9 @@ function datetimeToCalendarTime(
268230 * Jan 20 within the past year
269231 * Jan 20, 2019 anything over 1 year
270232 */
271- function datetimeToRelative ( locale : Locale | undefined , datetime : string ) : string {
272- const date = getLocalDateFromDatetime ( locale , datetime ) ;
273- const now = getLocalDateFromDatetime ( locale ) ;
233+ function datetimeToRelative ( locale : Locale | undefined , datetime : string , currentSelectedTimezone : SelectedTimezone ) : string {
234+ const date = getLocalDateFromDatetime ( locale , currentSelectedTimezone , datetime ) ;
235+ const now = getLocalDateFromDatetime ( locale , currentSelectedTimezone ) ;
274236 return formatDistance ( date , now , { addSuffix : true } ) ;
275237}
276238
@@ -338,12 +300,12 @@ function startCurrentDateUpdater() {
338300 } ) ;
339301}
340302
341- function getCurrentTimezone ( ) : Required < Timezone > {
303+ function getCurrentTimezone ( timezone : Timezone ) : Required < Timezone > {
342304 const currentTimezone = Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ;
343305 if ( timezone . automatic && timezone . selected !== currentTimezone ) {
344- return { ...timezone , selected : currentTimezone as SelectedTimezone } ;
306+ return { ...timezone , selected : currentTimezone as SelectedTimezone , automatic : timezone . automatic ?? false } ;
345307 }
346- return timezone ;
308+ return { selected : timezone . selected ?? ( CONST . DEFAULT_TIME_ZONE . selected as SelectedTimezone ) , automatic : timezone . automatic ?? false } ;
347309}
348310
349311/**
0 commit comments