question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Time zone issue causing hour and minutes to be off

See original GitHub issue

Hi,

Having an issue with time-zone (using 2.2.2). If TZ = Asia/Kuala_Lumpur the time will always be off by 30minutes. Example (just outline):

const tz = moment.tz.guess();
const t = moment();
console.log(moment.tz(t,tz).format("HH:mm"));
<TimePicker
  timeZone={tz}
  time={t.format("HH:mm")}
  timeFormatter={this.formatTime}
/>

formatTime(timeObject) {
  // time object is off by 30 minutes
}

Set the machine to use Asia/Kuala_Lumpur as the TZ and the picker is off by 30 minutes. Using ‘material’ as rendering.

My complete setup of timepicker is:

    <TimePicker
      {...this.props}          
      focused={focused}
      meridiem={meridiem}
      onFocusChange={this.onFocusChange}
      onHourChange={this.onHourChange}
      onMeridiemChange={this.onMeridiemChange}
      onMinuteChange={this.onMinuteChange}
      onTimeChange={this.onTimeChange}
      timeFormatter={this.formatTime}
      timezone={tz}
      showTimezone={false}
      time={moment(this.props.time).format("HH:mm")}
      trigger={this.trigger}
      useTz={true}
      theme='material'
    />

Also when setting showTimezone={true} react bails out. warning.js?8a56:36 Warning: Failed prop type: Invalid prop children supplied to CSSTransitionGroupChild, expected a ReactNode. in CSSTransitionGroupChild (created by TransitionGroup) in TransitionGroup (created by CSSTransitionGroup) in CSSTransitionGroup (created by Timezone) in div (created by Timezone) in Timezone (created by TwentyFourHoursMode) in div (created by TwentyFourHoursMode) in TwentyFourHoursMode (created by MaterialTheme) in div (created by MaterialTheme) in MaterialTheme (created by TimePicker) in div (created by OutsideClickHandler) in OutsideClickHandler (created by TimePicker) in div (created by TimePicker) in TimePicker (created by TimePickerWrapper)

Screenshot (correct time is the OS clock in upper right corner): image

Br Fredrik

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
gnilkcommented, Dec 6, 2017

Reopening this after some more digging. Reason: Certain time-zones (esp. in Asia) have offsets depending on the date (i.e. Singapore/Kuala Lumpur) - guessing the time-zone without passing in a fully qualified date/time object can’t possibly work (unless I am again missing something).

I believe this is part of the problem (from time.js/getValidTimeData): const formatTime = moment(1970-01-01 ${validTime}, YYYY-MM-DD ${hourFormat}, ‘en’);

For Singapore and KualaLumpur this will cause 30min off. As they changed their offset in 1982. See: https://github.com/moment/moment-timezone/issues/490

A potential fix could be to pass in a reference date which is used instead of 1970-01-01. IMHO - the best would be to pass in time as a moment object directly. As there is anyway a dependency on moment within the code. OR remove any TZ handling within the library and let the caller handle it.

Br Fredrik

0reactions
gnilkcommented, Dec 7, 2017

If changed to ‘let user deal with it’ - you would break backwards compatibility, which is problematic in itself.

One option would be to have a property called ‘reference time’. Default this property to currently used 1970-01-01. This would retain backwards compatibility but also allow for users to override. In my case I would simply set it to ‘moment()’.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix It When the Time on Your Phone Is Wrong - Lifewire
The most likely reason is that the time zone is misconfigured, either because you set it manually or incorrectly. When the wrong time...
Read more >
Is Your Windows 10 or 11 Time Wrong? Here's How to Fix the ...
When your computer clock is off by exactly one or more hours, Windows may simply be set to the wrong time zone. Even...
Read more >
Why are time zones different in terms of hours and not minutes?
The whole point of time zones is to make things constant, and having a time zone offset of, say, 5 hours, 13 minutes...
Read more >
How To Fix a Windows Clock Set To the Wrong Time - Alphr
If your computer clock shows the right hour, but the minutes are off, then the issue might be poor time synchronization settings. However,...
Read more >
iOS 12 Time Off by an hour (timezone issu… - Apple Community
iOS 12 Time Off by an hour (timezone issues) · Tap Time Zone and enter a city with the time zone that you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found