mineschan / MZTimerLabel

A handy class for iOS to use UILabel as a countdown timer or stopwatch just like in Apple Clock App.
MIT License
1.57k stars 247 forks source link

Timezone Issue #76

Open fjcaetano opened 8 years ago

fjcaetano commented 8 years ago

We're using the timer labels as countdowns to deadline dates. However, whenever a deadline is in two different days because of timezone differences, the label shows the incorrect number of days remaining.

Example: If a deadline is set to 2016-06-23 1am (UTC), if the device's timezone is UTC-4, the deadline would end at 2016-06-22 9p.m (UTC-4). And instead of the label showing "0d 2h 27m" it shows "1d 2h 27m".

We were able to fix this issue by removing this line that reads.

        [_dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];

However we don't know how this change would impact other users, so we didn't apply for a pull-request yet.

ankraft commented 8 years ago

My opinion is that the time zones of the supplied dates should apply. Is there a reason that the line mentioned sets the time zone explicitly?

fjcaetano commented 8 years ago

The problem is that the supplied timezone is being applied, but the device's timezone is being ignored, which creates the issue described.

Both should be used to calculate the correct time difference, but when the "GMT" timezone is given to the formatter, it assumes the device is in the +0 timezone which, not necessarily, is true and the time difference calculated is towards the GMT timezone and not the true timezone where the device is.

That's why I said that removing that line solves the issue, because the device's timezone starts being taken into account.

ankraft commented 8 years ago

What I meant: I agree with you. Applying "GMT" for only one date (start or target) would break the date calculations. I am using the timer label only in stopwatch mode in my app, not countdown, so I cannot give you any advice. But I guess the fix you suggested can easily be tested for various time zones with the demo app.