CPTimeZone issue on Windows PC vs Mac

已查看 27 次
跳至第一个未读帖子

bartels76

未读,
2016年5月11日 18:23:132016/5/11
收件人 Cappuccino & Objective-J
Just wanted to validate with the group.

When a CPTimeZone is initialized it parses the timezone from the string.

    var date = [CPDate date],
        abbreviation = String(String(date).split("(")[1]).split(")")[0];

On a Mac abbreviation parses to "CDT" and on a PC it parses to "Central Daylight Time"

On the Mac the lookup is successful, for the PC it will return nil because the full name is not found in the abbreviationDictionary.

To fix it I created a full name to abbreviation dictionary.  if the parsed abbreviation is larger than 4 characters it will attempt to lookup the abbreviation from the new dictionary.

    var fullNameToAbbreviationDictionary = @{
        @"Atlantic Daylight Time"           :   @"ADT",
        @"Alaska Daylight Time"             :   @"AKDT",
        @"Alaska Standard Time"             :   @"AKST",
        @"Argentina Standard Time"          :   @"ART",
        @"Atlantic Standard Time"           :   @"AST",
        @"Bangladesh Standard Time"         :   @"BDT",
        @"Brasilia Standard Time"           :   @"BRST",
        @"Brasilia Standard Time"           :   @"BRT",
        @"Greenwich Mean Time"              :   @"BST",
        @"Central Africa Time"              :   @"CAT",
        @"Central Daylight Time"            :   @"CDT",
        @"Central European Standard Time"   :   @"CEST",
        @"Central European Standard Time"   :   @"CET",
        @"Chile Standard Time"              :   @"CLST",
        @"Chile Standard Time"              :   @"CLT",
        @"Colombia Standard Time"           :   @"COT",
        @"Central Standard Time"            :   @"CST",
        @"East Africa Time"                 :   @"EAT",
        @"Eastern Daylight Time"            :   @"EDT",
        @"Eastern European Standard Time"   :   @"EEST",
        @"Eastern European Standard Time"   :   @"EET",
        @"Eastern Standard Time"            :   @"EST",
        @"GMT"                              :   @"GMT",
        @"Gulf Standard Time"               :   @"GST",
        @"Hong Kong Standard Time"          :   @"HKT",
        @"Hawaii-Aleutian Standard Time"    :   @"HST",
        @"Indochina Time"                   :   @"ICT",
        @"Iran Standard Time"               :   @"IRST",
        @"India Standard Time"              :   @"IST",
        @"Japan Standard Time"              :   @"JST",
        @"Korean Standard Time"             :   @"KST",
        @"Mountain Standard Time"           :   @"MDT",
        @"Moscow Standard Time"             :   @"MSD",
        @"Moscow Standard Time"             :   @"MSK",
        @"Mountain Standard Time"           :   @"MST",
        @"New Zealand Daylight Time"        :   @"NZDT",
        @"New Zealand Standard Time"        :   @"NZST",
        @"Pacific Daylight Time"            :   @"PDT",
        @"Peru Standard Time"               :   @"PET",
        @"Philippine Standard Time"         :   @"PHT",
        @"Pakistan Standard Time"           :   @"PKT",
        @"Pacific Standard Time"            :   @"PST",
        @"Singapore Standard Time"          :   @"SGT",
        @"GMT"                              :   @"UTC",
        @"West Africa Standard Time"        :   @"WAT",
        @"Western European Standard Time"   :   @"WEST",
        @"Western European Standard Time"   :   @"WET",
        @"Western Indonesia Time"           :   @"WIT"
        };

    var date = [CPDate date],
        abbreviation = String(String(date).split("(")[1]).split(")")[0];

    if (abbreviation && abbreviation.length > 4)
        if ([fullNameToAbbreviationDictionary containsKey:abbreviation])
            abbreviation = [fullNameToAbbreviationDictionary valueForKey:abbreviation];


Should I file a bug for this?

Thanks,
Jeremy

Martin Carlberg

未读,
2016年5月12日 04:39:522016/5/12
收件人 objec...@googlegroups.com
Hi!

Yes, if you have a problem and this will solve it please create a pull request with this code. You can read more about contributing to the Cappuccino project here http://www.cappuccino-project.org/contribute.html and here https://github.com/cappuccino/cappuccino/blob/master/CONTRIBUTING.md

It should help a lot if you can include some test cases for this. I understand that this problem might depend on what type of computer you are running on but try to do test cases that is independent of that.

Thanks for finding this problem and contributing to Cappuccino.

- Martin


--
You received this message because you are subscribed to the Google Groups "Cappuccino & Objective-J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to objectivej+...@googlegroups.com.
To post to this group, send email to objec...@googlegroups.com.
Visit this group at https://groups.google.com/group/objectivej.
For more options, visit https://groups.google.com/d/optout.

回复全部
回复作者
转发
0 个新帖子