react-native-localize icon indicating copy to clipboard operation
react-native-localize copied to clipboard

usesAutoDateAndTime() returns true if i turned off my auto time and date setting and does not change date or time.

Open mashad6 opened this issue 2 years ago • 8 comments

Bug summary

I was working with usesAutoDateAndTime() and noticed that if i turned off the setting and does not change any time or date, the function still returns me true, thou it should be false. The boolean only updates its value when we changes the time or date.

Also there's also a problem that if i turned off the auto time and date setting and changes the date, and then view logs it gives false(which is ok) but then if i manual corrects the date and turn on the setting again, it still gives me false.

I tried using Listeners, but it wont work on auto time&date setting

Library version

2.2.0

Environment info

System:
    OS: macOS 11.6.1
    CPU: (8) x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
    Memory: 2.24 GB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.14.0 - /usr/local/bin/node
    Yarn: Not Found
    npm: 8.3.1 - /usr/local/bin/npm
    Watchman: 2021.10.18.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.0.1, iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0
    Android SDK:
      API Levels: 23, 28, 29, 30, 31
      Build Tools: 28.0.3, 29.0.2, 30.0.2, 30.0.3, 31.0.0
      System Images: android-19 | Google APIs ARM EABI v7a, android-19 | Google APIs Intel x86 Atom, android-30 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 2021.1 AI-211.7628.21.2111.8139111
    Xcode: 13.1/13A1030d - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_292 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: ^17.0.2 => 17.0.2 
    react-native: ^0.67.0 => 0.67.2 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

  1. Initially turn on you auto time&date setting
  2. see the logs
  3. turn off your auto time&date setting
  4. see the logs

Reproducible sample code

<TouchableOpacity onPress={()=>console.log(RNLocalize.usesAutoDateAndTime())} ><Text>check setting</Text></TouchableOpacity>

mashad6 avatar Mar 03 '22 11:03 mashad6

@mashad6 Did you restarted the app before checking it again?

zoontek avatar Mar 03 '22 13:03 zoontek

@zoontek yes i did, i tried rebuilding the app as well. its easily reproducible .

mashad6 avatar Mar 06 '22 10:03 mashad6

I tried it and it works as currently expected.

Go to settings, untick auto date:

Screenshot 2022-03-06 at 12 29 59

The kill the app, restart it:

Screenshot 2022-03-06 at 12 31 41

These methods responses are currently not updated though time. I'm waiting for wide availability of React Native JSI to make theses synchronous though threads.

zoontek avatar Mar 06 '22 11:03 zoontek

@zoontek Well i did not kill the app, I used Appstate and called the function in it. so what it does is when my app goes to the settings and open app(with out killing) again, functions inside Appstate runs again . And usesAutoDateAndTime() is in it and doesnt returns the updated response

mashad6 avatar Mar 07 '22 05:03 mashad6

These can't be achieved for now since the response is synchronous.

zoontek avatar Mar 07 '22 07:03 zoontek

can you add any listener for this setting?

mashad6 avatar Mar 07 '22 10:03 mashad6

Unfortunately no. Inner BroadcastReceiver onReceive are currently not triggered on latest Android versions, external cannot access to React context.

The only way would be to add async methods for everything (ex: usesAutoDateAndTimeAsync: Promise<boolean>, etc.), but it's verbose and error prone. As JSI is around the corner (already present in latest react native versions, just hidden / not documented), it will be better to just wait for wide availability to make some breaking changes and switch to it entirely.

As it's not something people change every day, it's - I think - OK for now.

zoontek avatar Mar 07 '22 11:03 zoontek

@zoontek Thanks man for the clarity. appreciate it.

mashad6 avatar Mar 07 '22 11:03 mashad6

@zoontek good morning . Congratulations for the initiative.

I'm developing an application in react where the automatic date and time information will be used to allow or disallow a user action, so I need it to reflect exactly what is set at the time of registration.

Are you thinking of working on something along these lines?

ssimoes avatar Dec 06 '22 11:12 ssimoes