I need confirmation regarding timezone displaying EST - ios

I am wondering if the code below will correctly display Eastern time correctly no matter what (day light savings or when it isn't day light savings). Right now my App isn't displaying data correctly because of day light savings. This code seems to work well now, but I don't want to find out in a few months that this time doesn't adjust correctly.
[NSTimeZone timeZoneWithName:#"US/Eastern"]

Yes,
For March 10 2015, it displays
US/Eastern (EDT) offset -14400 (Daylight)
For March 1 2015, it displays
US/Eastern (EST) offset -18000

Related

iOS : How to check if date-time selected is valid time during day light savings?

I have a special case to check where a user inputs the future date and time and I need to verify if that time is valid (what do I mean by valid is explained below) considering user might be affected by daylight saving in his timezone.
For Example:
Assume the user's timezone is Adelaide, Australia. Open the link to see how timezone affects in Adelaide OR see below.
4 Oct 2020 - Daylight Saving Time Starts
When local standard time is about to reach
Sunday, 4 October 2020, 2:00:00 am clocks are turned forward 1 hour to
Sunday, 4 October 2020, 3:00:00 am local daylight time instead.
Now based on the above information my understanding is if my user selected the date-time between
4 October 2020, 2:01:00 am - 4 October 2020, 2:59:00 am
it's not valid as the hour is forwarded to 3 am.
How can I validate that in an iOS app? (Assuming i)
Basically I need to inform the user that the time selected is affected by DST and users need to select a different time.
I've looked into Date and Timezone APIs and couldn't seem to find anything which can validate this.
Thanks in advance, any help would be appreciated.
I guess the easiest way would be to convert the string (or whatever the user enters, seems you are not using the UIDatePicker) into a date and check if this is possible.
For Mid-Europe, DST is starting on March 29th, 2020, so
let df = DateFormatter()
df.locale = Locale(identifier: "de_DE")
df.timeZone = TimeZone(identifier:"Europe/Berlin")
df.dateFormat="yyyy-MM-dd hh:mm"
if let theDate = df.date(from: "2020-03-29 02:01")
{
print(theDate)
} else {
print ("Illegal date")
}
will print Illegal date.
A little more tricky is switch back to non-DST, because (in Mid-Europe) there are two possible dates for 2020-10-25 02:01 - it could mean winter or summer time with two different UTC representations.

Will convert_timezone 'America/New_York' work regardless of my timezone's offset depending on time of year?

My timezone is -4 or -5 from GMT depending on time of year. Currently it is -4.
If I use this code below, will it automatically switch when we change to -5?
select convert_timezone('America/New_York', CAST(json_extract_path_text('{"timestamp":"2019-04-16T03:30:00.704Z"}', 'timestamp') as TIMESTAMP));
Currently the line above returns a date of 2019-04-15.
But if I make this call in December (note the time has +1 hour),
will it still return a date of 2019-04-15.
select convert_timezone('America/New_York', CAST(json_extract_path_text('{"timestamp":"2019-04-16T04:30:00.704Z"}', 'timestamp') as TIMESTAMP));
In other words, will it switch between EDT and EST without intervention? Or is there a better way?
Thanks
Consider:
2019-04-16T03:30:00.704Z (UTC) in America/New_York is 2019-04-15T23:30:00.704-04:00
2019-04-16T04:30:00.704Z (UTC) in America/New_York is 2019-04-16T00:30:00.704-04:00
2019-12-16T04:30:00.704Z (UTC) in America/New_York is 2019-12-15T23:30:00.704-05:00
For US Eastern Time, a date in April will be in -4 while a date in December will be in -5. In other words, the timestamp being converted is what determines which offset to apply.
The date and time that the code executes has no relevance.

JTCalendar showing wrong date in Calendar

I make JTCalendar into custom view , all thing were working fine until I change timezone to EST, the calendar is showing 27 days for February but the actual number of days in 2018 is 28.
It happen when I start the app in default timezone and then changing the timezone to New York from settings, then when I open calendar, layout is wrong. After this when I tap into date 24 and result is date 23. only happen when I change timezone from IST to EST.

Format time to show day and month

For a project I am working on I receive date and time in this format:
2015-08-16 15:00:00 UTC
yyyy-mm-dd hh-mm-ss UTC
How can I make the time display as "Saturday, August 16th 2015 at 3:30PM"? ("15:00" would be fine as well.)
And how would I make it so it checks if the date has already passed or not, so that it only displays dates that have not passed?
How would I make it so I can so that the time display as "Saturday, August 16th 2015 at 3:30PM (15:00 would be fine as well)?
Time.parse('2015-10-20 15:23 UTC').strftime('%A, %B %dth %Y at %l:%M%p')
#=> "Tuesday, October 20th 2015 at 3:23PM"
You might have to tweak it a bit to fix the suffixes (1st, 2nd, 3rd, etc)
And how would I make it so it checks if the date has already pasted or not?
You could do it like this (I'm sure there's a simpler way):
EDIT: Yes, there is a much simpler way -- check Matt's answer.
require 'time'
if Time.parse(my_date).to_i - Time.now.to_i > 0
# my_date is in the future.
end
To start, convert your string to a Time object via Time.parse(string) (APIDock).
After that you have all of the Time class to play with.
time.strftime
time.past?

secondsFromGMT returns different values on device and simulator

I am working on a time app which display time of different time zones. For this i am using a standard time haDate (UTC tz).
For displayDate i am using system time zone api. Time Zone is America/Santiago (UTC-3:00).
NSTimeZone *tz=[NSTimeZone timeZoneWithName:_timeZone];
_displayDate=[_haDate dateByAddingTimeInterval:tz.secondsFromGMT];
"haDate" code -
NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
formatter.timeZone=[NSTimeZone timeZoneWithName:#"UTC"];
NSString *utcTimeCurrent=[dict objectForKey:#"utctime"];
[formatter setDateFormat:#"yyyy-MM-dd HH:mm:ss"];
_haDate=[formatter dateFromString:utcTimeCurrent];
The issue is when i run this code on simulator tz.secondsFromGMT returns -10800 but on device it returns -14400, which is 1 hour less.
Device and Simulator using same timeZone Asia/Kolkata (UTC+5:30). I know America/Santiago uses DST but why it is giving me different seconds even both (simulator and device) are on same timeZone.
What is wrong and how can i fix it?
NOTE
To fix DST issue i am using this code. But it always go to the else part on both devices. (BTW below code is not required because tz.secondsFromGMT always return seconds after DST adjustments.)
NSTimeZone *tz=[NSTimeZone timeZoneWithName:_timeZone];
if (tz.isDaylightSavingTime)
{
_displayDate=[_haDate dateByAddingTimeInterval:tz.secondsFromGMT+tz.daylightSavingTimeOffset];
}
else
{
_displayDate=[_haDate dateByAddingTimeInterval:tz.secondsFromGMT];
}
When i log the tz -
On Simulator
tz America/Santiago (GMT-3) offset -10800
On Device
tz America/Santiago (GMT-4) offset -14400
So it is not using DST.
NOTE 2
This problem only occurs in iPad 2. Other devices working fine.
NOTE 3
My iPad 2 using iOS 8.4 . Both time zones (Chile Standard Time -America/Santiago and Easter Island Standard Time - Pacific/Easter) are giving me wrong seconds
Chile changed the TZ at the beginning of 2015. Probably your iPad 2 has an iOS Version using an outdated time zone database. Update it.
Time in Chile is divided into two time zones. Continental Chile uses the time offset UTC−03:00. Additionally, Easter Island uses the time offset UTC−05:00.[1]
Until 2015, Continental Chile used the time offset UTC−04:00 and Easter Island used UTC−06:00 for standard time, with daylight saving time roughly between October and March every year. However, in January 2015 it was announced that all the country will keep the time offset used during daylight saving time.
https://en.wikipedia.org/wiki/Time_in_Chile

Resources