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

Wrong time for UTC -ve values #47

Open
Nissimarcus11 opened this issue Sep 10, 2021 · 1 comment
Open

Wrong time for UTC -ve values #47

Nissimarcus11 opened this issue Sep 10, 2021 · 1 comment

Comments

@Nissimarcus11
Copy link

Showing wrong time for New York

@Nissimarcus11
Copy link
Author

try{
      // make the request
      Response response = await get('http://worldtimeapi.org/api/timezone/$url');
      Map data = jsonDecode(response.body);

      // get properties from json
      String datetime = data['datetime'];
      String offset = data['utc_offset'].substring(1,3);
      String sign = data['utc_offset'].substring(0,1);
      print("sign is $sign");

      // create DateTime object
      DateTime now = DateTime.parse(datetime);
      now = sign == '+'? now.add(Duration(hours: int.parse(offset))):now.subtract(Duration(hours: int.parse(offset)));

      // set the time property
      isDaytime = now.hour > 6 && now.hour < 20 ? true : false;
      time = DateFormat.jm().format(now);
    }

Add ternary operator to read UTC value and add/substract based on that

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

1 participant