is iphone timezones reliable? Alternatives? - ios

I am currently writing an app that needs to represent some data arranged by local time. Since I don't think relying on [NSDate date] is a good idea at all, because the user can change his time wrongly, hence messing up my data. I then thought it would be better to make a timestamp (server time) and then represent the data comparing the difference between my timestamp timezone and users timezone. Am I right doing it this way?
Obviously this needs pretty much full reliance on timezones given by iOS are correct. If no, are there any better alternatives (like google timezone api?) (I would think they are both based on tz_database though?)
Thanks for any input

Related

Rails app on Ubuntu 12.0.4, tzdata 2016j pulling incorrect time zone abbreviations

I'm wondering if anyone else is seeing an issue with specific time zone abbreviations in their Rails apps on Ubuntu 12.0.4 boxes with tzdata 2016j.
For Asia/Yerevan, Asia/Istanbul, and Asia/Baku I seem to be getting incorrect Time Zone abbreviations - Time.now.in_time_zone will display the time with zone abbreviations: +04, +03, +04 when running the app on Ubuntu 12.0.4, whereas on my Mac (OS X El Capitan), I'm seeing AMT, EET, and AZT respectively (looks like Istanbul is getting incorrect time zone there).
If you're on any other version of Ubuntu or tzdata, I'd also appreciate any insight into what time zone abbreviations you get for these zones. I'm still trying to figure out which part of the stack is causing the issue.
Also, if anyone has a workaround, I'd greatly appreciate any insight there as well.
The source data itself has been changed. Over the last several releases, the TZ maintainers have been removing abbreviations that were previously invented or otherwise unsubstantiated.
The fact of the matter is that the idea of a "time zone abbreviation" is not a universal concept. We'd like to think that everyone around the world uses them, but really they don't. And when they do, they do not necessarily mean the same things as we think they do, or are the chosen abbreviations used universally. For example, A person in Minsk might happen to use the same UTC offset as a person in Moscow, but Moscow's use of MSK is well-known. Applying it to Minsk could be taken as an insult. Indeed, the TZDB used to use MSK for "Minsk Time", until this recent set of changes started.
It gets even more complicated when you think about abbreviations in other langugages.
If you have documentation to show that an abbreviation is actually used by those who live in the place in question (i.e., do people in Baku actually say "AZT"), then please present your findings on the discussion mailing list at IANA.
If you're just trying to get back what you had before - you'll have to make a list of your own "invented" abbreviations and refer to that. The TZDB is clear that it no longer wants to be the source of misinformation.
The better option, IMHO, is just to avoid using time zone abbreviations at all.

High-precision timer in iOS

What is the most precise way to measure time intervals in iOS? So far I have been using NSDate to "mark" events and then timeIntervalSinceDate method to calculate the interval, but is there more precise approach? E.g. Windows has so called QPC for that kind of thing. Is there something similar in iOS (or MacOSX) world?
You can get down to nanoseconds using mach_absolute_time(). Here is an article on using it:
https://developer.apple.com/library/mac/qa/qa1398/_index.html
It also exists on iOS.

Is AddThisEvent's timezone (zonecode) arbitrary?

I have users stored in the database and need to save a timezone to associate with the user so that I can use it to create events with AddThisEvent and to display other localized times.
Is the mapping from a timezone offset to the AddThisEvent zonecode arbitrary- or is he using some standard that I couldn't find?
The documentation in Step 2 describes the list of available values for the _zonecode.
These appear to be Microsoft Windows time zones, as mentioned in the timezone tag wiki.
However, the actual integers assigned to each "Zonecode" appear to be proprietary to AddThisEvent. It's likely that they are using TimeZoneInfo.GetSystemTimeZones in .NET, and assigning each entry to an integer.
Hopefully, they realize that this list is not necessarily fixed. Microsoft can provide updates which add entries to Windows when new time zones need to be created. For example, two new time zones are being added soon for the upcoming October 2014 Russian time zone changes. These would be added in the middle of the list, so the list would no longer be sequential. If they are just using an index value of the array returned, they'll be surprised when the changes cause everything to shift forward.
(Note - I have no special knowledge of how AddThisEvent is actually planning to handle updates. I am just speculating.)
In general - integers are not good time zone identifiers.
So what should I do then?
Map each of the proprietary entries back to the Windows time zone they belong to. Then, if necessary, map them to the standard IANA TZ identifier used by PHP, Python, Java, etc. You can use the CLDR mappings to determine an appropriate TZ identifier to use for each Windows time zone.
It's a shame you'll have to jump through so many hoops, but in the end, you'll be able to figure out the appropriate integer to use with AddThisEvent for each user.
It looks like AddThisEvent has already updated their timezone handling. However, if people are still using the older library and are running into this problem, one solution is to convert the datetime to UTC before passing it to AddThisEvent. Then you can use the _zonecode 35 (UTC). Calendar options like Google, Outlook, etc should be able to convert from UTC to the user's timezone appropriately.

Is there a database of time zone lines available for download?

I've searched and found a couple of online web services that do this, but I was wondering it there's a database in the public domain which gives a list of latitudes and longitudes for the standard time zone lines? I'd like to be able to calculate what time zone a coordinate is without using a web service. I figured that time zone boundaries are mostly static and were probably decided by some committee, so there should be a CSV or GPX or KML somewhere.
I'd like to be able to check what time zone a coordinate lies in, for example:
48.856667 2.350833 is GMT+1 or CET
This is a series of files -- timezone polygons (shapefile), which you can transform into boundaries. With work on your part.
http://efele.net/maps/tz/world/
You should note that simply knowing the TZ does not guarantee that you know anything about the current correct time or date there in terms of the local calendar. Time Ex: The Isreali Knesset (parliament) decides when Daylight time starts and ends - sometimes they have chosen a date in the past. Date Ex: The Hijri Calendar changes months based on the ability of people in Mecca to actually observe the new moon from there. Cloudy days alter the date.
Askgeo.com has a Java library under commercial license. (Scroll down their page to find information about it). They charge 2 grand up front for it though, considering the amount of work they must have put in compiling loads of vector maps, etc, I can understand they want the money.
I use their free API, but you wanted something downloadable, and I think this is one of your few bets.
I tried openstreetmap and they have the data, but it would be buried in a map of Earth, not completely useful itself. Here is one on Wikipedia though: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
I recently found this data here:
https://github.com/straup/whereonearth-timezone

Guessing the time zone from an arbitrary "location" string?

I'm trying to run some statistics over the Stack Overflow data dump, and for that I would like to know the time zone for each user. However, all I have to go on is the completely free-form "location" string.
I'll stress that I'm only looking for an approximation of the time zone; of course, in general this is an unsolvable problem. However, many people fill out their country, state and/or city, which should give a pretty good indication. It's okay if it fails for other cases. It doesn't have to be reliable, it doesn't have to be accurate, it doesn't have to cover all bases.
I don't want to waste too much time on this, so I'm wondering if there is some code out there that can make a reasonable guess. Any language, platform, API or library goes. Any ideas?
Check this discussion for information on how to get the lat/lon from an arbitrary location string.
Once you have the lat/lon, you can use the web services at GeoNames to retrieve the time zone.

Resources