Does iOS 6 support the timezone PHT when trying to use NSDateFormat? - ios6

I am having problems with my code and not sure what is wrong with it.
NSString* dateFormat1 = #"EEE MMM dd HH:mm:ss V yyyy";
NSString* dateString1 = #"Fri Jul 26 00:00:00 PHT 2013";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:dateFormat1];
My result for iOS5.1:
2013-08-02 11:59:08.459 MySandbox[41502:c07] 2013-07-25 16:00:00 +0000
For iOS 6.0
2013-08-02 12:02:37.454 MySandbox[41581:c07] (null)
*Note, I used V, instead of zzz or Z because it still is null.
*Note 2, I tried to change PHT to PST and it worked. Changed it to JST, it didn't work.
I am guessing that I am not using the correct format. Not really sure which I should use.
*Note 3, as per this question, there really was a change in iOS5 and iOS6 so I guess that is the reason why iOS5 worked.

According to these docs from Apple, NSDateFormatter uses the Unicode date format patterns, which are part of "Unicode Technical Standard #35". This standard is evolving, and iOS 5 uses version 19 while iOS 6 uses version 25.
You can read about the supported values for the time zone in "Appendix J: Time Zone Display Names" (version 19 or version 25).
I am not exactly sure why PHT was supported before and not it isn't. But in general, the best advice I can give is to avoid using time zone abbreviations. While PHT is unique, there are many other abbreviations that are ambiguous. See the list here.
Instead, you should uses the IANA time zone name whenever possible. (The tr-35 standard calls this the "Golden Zone"). In your case, it would be Asia/Manila. You can find a full list here. I am not an Objective C developer, so I'm not sure exactly how you would use this in your input string. You can try the VVVV format specifier, but I'm not sure if it directly accepts the IANA name or not.
You might want to check the results from [NSTimeZone abbreviationDictionary] as shown in this answer. In that post, it does show PHT = "Asia/Manila", but I assume by the date that it was posted that these were generated from iOS 5.

Related

Can anyone help me identify this timestamp format?

I am importing information from an Oracle database on an AIX machine into SQL Server 2008r2. I inherited this process from the previous DBA. The timestamp comes in the following format: 4170180534, which, based on the conversion function in the executable, converts to the following:
417 = year (2017)
018 = days since beginning of year (018 converts to Jan 18)
0534 = time HH:mm
I need to provide maintenance on the conversion function (the previous DBA retired in 2016, so the date conversion function only works through the end of 2016).
Can anyone tell me exactly what this timestamp format is? I assume the '4' stands for the century, but it would be nice to know for sure what the first digit of the value actually is.
4should stand for weeks since start of year
format for that would be
(weeks since 1st jan, 2last digits of year, days since 1st jan, hours, minutes)
WW IY DDD HH MI

Why timezone in angular doesn't work as expected in the following case

I'm using legacy AngularJS 1.3
I have the following code
{{ (1475586000*1000) | date:'yyyy-MM-dd' : 'Australia/Lord_Howe'}}
In UTC, 1475586000 is 04 Oct 2016 13:00:00 GMT
Since Australia/Lord_Howe is +11, I expect 2016-10-05 should be printed.
However, 2016-10-04 is printed. May I know why?
From the docs for AngularJS v1.3.19 ...
Timezone to be used for formatting. Right now, only 'UTC' is
supported. If not specified, the timezone of the browser will be used.
Looking at the documentation for the latest 1.5 release ...
Timezone to be used for formatting. It understands UTC/GMT and the
continental US time zone abbreviations, but for general use, use a
time zone offset, for example, '+0430' (4 hours, 30 minutes east of
the Greenwich meridian) If not specified, the timezone of the browser
will be used.
... which gives the clue that you can get closer to what you want by using an offset, although that presumably gives daylight savings issues so it is not the same thing:
{{ (1475586000*1000) | date:'yyyy-MM-dd' : '+11:00'}}

String to UTC date in C/Windows API

I'm working in native C (not C++ - I'd like for everything to stay in C as much as possible) on the Windows API and I'm having trouble with dealing with/comparing UTC strings. Basically I'm getting a date from a WMI call, which as I understand it is a UTC number returned as a DWORD, and I'd like to take a human-readable date-time (i.e. 11:11:11 08/04/2014) and compare that to the UTC date I already have so I can programmatically say which comes before the other.
However it doesn't look like the Windows API provides a good API, and I tried to do it using sscanf_s and mktime similar to the second answer here. This gave me a number that seem close but wasn't quite correct. i.e. both will be today's date within a few minutes has the most significant 3-4 digits the same but nothing else is close.
Is this a timezone/local time problem? Or am I just missing something?

Check if DST is on according to UTC time in sql

I am working in MVC4 project where i am facing problem with time.Actually my project requirement is to show all time used in application according to Brazil time.So i have used GETUTCDATE() for saving time in application.
Now i want to check if DST is on according to time i saved..i mean central time. How do i check this.
I have search on net and found one solution
DECLARE #IsDST BIT;
SET #IsDST = CASE WHEN DateDiff(hour, GetDate(), GetUTCDate()) = 4 THEN 'True'
ELSE 'False' END;
SELECT GETDATE() AS GETDATE,
GETUTCDATE() AS GETUTCDATE,
#IsDST;
But when i try to run this script,it return false ??
But as per DST calculation,it always starts from 2nd Sunday of March and ends on 1st Sunday of November.
Then it should return true ,that DST is on.
Am i doing right or is there another better approach to check if DST is on central time,so that i can show brazil time according to DST
Well, this particular code doesn't work for detecting DST in Brazil, because it just measures the difference right now between local time and UTC, checking for 4 hours difference or not.
Most of Brazil is 3 hours behind UTC in the standard time, and 2 hours behind UTC in the daylight time. So this code probably won't work for you. You can read more in this Wikipedia article.
Daylight Saving Time is very different all over the world, so if you intend to use this approach then you will have to modify your code to match the time zone of the server that it's running on.
Personally, I would recommend not doing this in SQL at all. Time zone conversions aren't really the realm of the database. They work much better in application code. You should work with UTC in your database, and convert it to Brazil or whatever time zone you require in your application.
Since you said this was an ASP.Net MVC4 application, I recommend you either use the .net TimeZoneInfo class, or use the excellent Noda Time library to do your conversions in your .Net code.
Using TimeZoneInfo:
DateTime utcDT = // ... your UTC value returned from the database
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById(
"E. South America Standard Time"); // Brazil
DateTime brazilDT = TimeZoneInfo.ConvertTimeFromUtc(utcDT, tz);
Using Noda Time:
DateTime utcDT = // ... your UTC value returned from the database
Instant instant = Instant.FromDateTimeUtc(utcDT);
DateTimeZone tz = DateTimeZoneProviders.Tzdb["America/Sao_Paulo"]; // Brazil
ZonedDateTime brazilZDT = instant.InZone(tz);
DateTime brazilDT = brazilZDT.ToDateTimeUnspecified();

first day of the week in MacOS X with c

In Russia the first day of the week is Monday. In the United States - Sunday. On Linux nl_langinfo(_NL_TIME_FIRST_WEEKDAY) return 0 for Sun or 1 for Mon. How do I get too in MacOS X with c-code?
I haven't tried it myself, but from skimming the docs, you can get a CFLocale instance (reference) and get it's CFCalendar instance using:
CFLocaleGetValue(locale, kCFLocaleCalendar)
And get the first day of the week from the CFCalendar instance using CFCalendarGetFirstWeekday() (reference).
My guess would be to use CFDateRef and CFLocaleRef opaque types and associated CFDate* and CFLocale* functions from CoreFoundation framework.
UPDATE
After some digging I found the function you need. It appears that you have to use CFCalendar for this. From apple's documentation:
CFCalendarGetFirstWeekday
Returns the index of first weekday for a specified calendar.
CFIndex CFCalendarGetFirstWeekday (
CFCalendarRef calendar
);
Parameters
calendar
The calendar to examine.
Return Value
The index of the first weekday of the specified calendar.

Resources