Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

America/Sao_Paulo datetime behavior is wrong when debug mode is OFF using RN #126

Open
dotpegaso opened this issue Nov 1, 2019 · 4 comments

Comments

@dotpegaso
Copy link

dotpegaso commented Nov 1, 2019

Our current president has decided to cancel DST in Brazil this year. This means that since November 4th the timezone is being returned incorrectly (UTC -2 instead of -3).

I tried to use some libs to solve this problem:

"date-fns": "^2.6.0",
"date-fns-tz": "^1.0.8",
"moment": "^2.24.0",
"moment-timezone": "^0.5.27",

But I couldn't.

I also learned that React Native has 2 types of environments to run JS: V8 from Chrome when Debug Mode is ON and device's JavascriptCore when Debug Mode is OFF.

I've noticed that's influences directly in the timezone behavior, since when Debug Mode is ON, there's no problem with timezone at all using any of those libraries above.

I've also tried to solve this by installing "jsc-android": "241213.x.x" with all gradle config and stuff, but the timezone stills incorrect.

I can't find a solution to make timezone works as expected.


React Native version:

React Native Environment Info:
    System:
      OS: macOS 10.14.6
      CPU: (4) x64 Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz
      Memory: 111.66 MB / 8.00 GB
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 10.15.1 - /usr/local/bin/node
      Yarn: 1.13.0 - /usr/local/bin/yarn
      npm: 6.4.1 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
      Android SDK:
        API Levels: 21, 23, 27, 28, 29
        Build Tools: 23.0.1, 25.0.0, 25.0.2, 26.0.1, 26.0.2, 27.0.3, 28.0.2, 28.0.3, 29.0.0
        System Images: android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 3.4 AI-183.6156.11.34.5692245
      Xcode: 10.3/10G8 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3 
      react-native: 0.59.10 => 0.59.10 
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-git-upgrade: 0.2.7

Steps To Reproduce

import React, { Component } from 'react'
import { Text } from 'react-native'
import { parseISO } from 'date-fns'
import { zonedTimeToUtc } from 'date-fns-tz'

render(){
   const parsedDate = parseISO('2019-11-15 20:00:00');
   const znDate = zonedTimeToUtc(parsedDate, 'America/Sao_Paulo');

   return <Text>{`Date: ${znDate}`}</Text>
  // returns  Date: Fri Nov 15 2019 20:00:00 GTM-0200(-02)
}

Describe what you expected to happen:

   Date: Fri Nov 15 2019 20:00:00 GTM-0300(-03)
@dotpegaso
Copy link
Author

Solve this using react-native-v8

@bramski
Copy link

bramski commented Nov 25, 2020

Did this actually work for you?

@bramski
Copy link

bramski commented Nov 26, 2020

Nobody has touched this in a year @DanielZlotin will anyone be able to update the build to include the new brazil timezone support?

@dlebedynskyi
Copy link

Issue still seems to be present
Test case

const time = 1607370988273; // 4:56 PM Monday, December 7, 2020 (GMT-3), Time in São Paulo, State of São Paulo, Brazil
const d = new Date(time);
const timeZone = 'America/Sao_Paulo';

 actualJSWithTimezone: d.toLocaleTimeString('en-us', { timeZone }),
 expected: '4:56 PM',
 dayjs: dayjs(d).tz(timeZone).format('HH:mm:ss'),
  moment: moment(time).tz(timeZone).format('HH:mm:ss')

and test results are

{
"actualJSWithTimezone": "5:56:28 PM",  // INCORRECT
"d": 2020-12-07T19:56:28.273Z, 
"dayjs": "17:56:28", // INCORRECT
"expected": "4:56 PM", 
"moment": "16:56:28"  // Correct - uses custom timezone info
}

Moment is only library atm that can handle Brazil DLS changes due to not using JSC Intl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants