New: Added support for CPTimeZone and CPDateFormatter

- Added support for CPDateFormatter in Foundation
- Added support for CPTimeZone in Foundation
- Added support fo CPDateFormatter in nib2cib

Test app in Tests/Manual/CPDateFormatter
UnitTest in Tests/Foundation/CPTimeZoneTest.j
UnitTest in Tests/Foundation/CPDateFormatterTest.j
This commit is contained in:
Alexandre Wilhelm
2013-04-12 11:15:10 -07:00
parent 4c756c7cbf
commit 0bbaec0829
19 changed files with 6508 additions and 55 deletions
+11 -16
View File
@@ -30,6 +30,7 @@
@import <Foundation/CPDate.j>
@import <Foundation/CPDateFormatter.j>
@import <Foundation/CPLocale.j>
@import <Foundation/CPTimeZone.j>
@class CPStepper
@class CPApp
@@ -68,8 +69,7 @@ CPEraDatePickerElementFlag = 0x0100;
CPFont _textFont @accessors(property=textFont);
CPLocale _locale @accessors(property=locale);
//CPCalendar _calendar @accessors(property=calendar);
//CPTimeZone _timeZone @accessors(property=timeZone);
CPDateFormatter _formatter @accessors(property=formatter);
CPTimeZone _timeZone @accessors(property=timeZone);
id _delegate @accessors(property=delegate);
unsigned _datePickerElements @accessors(property=datePickerElements);
CPInteger _datePickerMode @accessors(property=datePickerMode);
@@ -187,7 +187,6 @@ CPEraDatePickerElementFlag = 0x0100;
_datePickerElements = CPYearMonthDayDatePickerElementFlag | CPHourMinuteSecondDatePickerElementFlag;
_timeInterval = 0;
_implementedCDatePickerDelegateMethods = 0;
_formatter = [[CPDateFormatter alloc] init];
[self setObjectValue:[CPDate date]];
_minDate = [CPDate distantPast];
@@ -207,6 +206,9 @@ CPEraDatePickerElementFlag = 0x0100;
if (!_locale)
_locale = [CPLocale currentLocale];
if (!_timeZone)
_timeZone = [CPTimeZone systemTimeZone];
_datePickerTextfield = [[_CPDatePickerTextField alloc] initWithFrame:[self bounds] withDatePicker:self];
[_datePickerTextfield setDateValue:_dateValue];
@@ -265,18 +267,12 @@ CPEraDatePickerElementFlag = 0x0100;
#pragma mark -
#pragma mark Setter
/*! Return the objectValue of the datePicker. The objectValue is made with the current formatter of the datePicker
/*! Return the objectValue of the datePicker. The objectValue should take the timeZoneEffect
*/
- (void)objectValue
{
// try
// {
// return [_formatter stringFromDate:_dateValue];
// }
// catch(e)
// {
return _dateValue
// }
// TODO : add timeZone effect. How to do it because js ???
return _dateValue
}
/*! Set the objectValue ofhe datePier. It has to be a CPDate
@@ -328,8 +324,10 @@ CPEraDatePickerElementFlag = 0x0100;
[self willChangeValueForKey:@"dateValue"];
_dateValue = aDateValue;
[super setObjectValue:_dateValue];
[self didChangeValueForKey:@"dateValue"];
[self didChangeValueForKey:@"objectValue"];
[self didChangeValueForKey:@"dateValue"];
[self sendAction:[self action] to:[self target]];
[self willChangeValueForKey:@"timeInterval"];
_timeInterval = (_datePickerMode == CPSingleDateMode)? 0 : aTimeInterval;
@@ -603,7 +601,6 @@ var CPDatePickerModeKey = @"CPDatePickerModeKey",
CPDatePickerElementsKey = @"CPDatePickerElementsKey",
CPDatePickerStyleKey = @"CPDatePickerStyleKey",
CPLocaleKey = @"CPLocaleKey",
CPFormatterKey = @"CPFormatterKey",
CPBorderedKey = @"CPBorderedKey",
CPDateValueKey = @"CPDateValueKey";
@@ -623,7 +620,6 @@ var CPDatePickerModeKey = @"CPDatePickerModeKey",
_datePickerElements = [aCoder decodeIntForKey:CPDatePickerElementsKey];
_datePickerStyle = [aCoder decodeIntForKey:CPDatePickerStyleKey];
_locale = [aCoder decodeObjectForKey:CPLocaleKey];
_formatter = [aCoder decodeObjectForKey:CPFormatterKey];
_dateValue = [aCoder decodeObjectForKey:CPDateValueKey];
_backgroundColor = [aCoder decodeObjectForKey:CPBackgroundColorKey];
_drawsBackground = [aCoder decodeBoolForKey:CPDrawsBackgroundKey];
@@ -646,7 +642,6 @@ var CPDatePickerModeKey = @"CPDatePickerModeKey",
[aCoder encodeObject:_dateValue forKey:CPDateValueKey];;
[aCoder encodeObject:_textFont forKey:CPTextFontKey];
[aCoder encodeObject:_locale forKey:CPLocaleKey];
[aCoder encodeObject:_formatter forKey:CPFormatterKey];
[aCoder encodeObject:_backgroundColor forKey:CPBackgroundColorKey];
[aCoder encodeObject:_drawsBackground forKey:CPDrawsBackgroundKey];
[aCoder encodeObject:_isBordered forKey:CPBorderedKey];
File diff suppressed because it is too large Load Diff
+630
View File
@@ -0,0 +1,630 @@
/* CPTimeZone.j
* Foundation
*
* Created by Alexandre Wilhelm
* Copyright 2012 <alexandre.wilhelmfr@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import "CPObject.j"
@import "CPString.j"
@import "CPDate.j"
@import "CPLocale.j"
CPTimeZoneNameStyleStandard = 0;
CPTimeZoneNameStyleShortStandard = 1;
CPTimeZoneNameStyleDaylightSaving = 2;
CPTimeZoneNameStyleShortDaylightSaving = 3;
CPTimeZoneNameStyleGeneric = 4;
CPTimeZoneNameStyleShortGeneric = 5;
CPSystemTimeZoneDidChangeNotification = @"CPSystemTimeZoneDidChangeNotification";
var abbreviationDictionary,
timeDifferenceFromUTC,
knownTimeZoneNames,
defaultTimeZone,
localTimeZone,
systemTimeZone,
timeZoneDataVersion,
localizedName;
/*!
@class CPTimeZone
@ingroup foundation
@brief CPTimeZone is a class to define the behvior of time zone object (like CPDatePicker)
*/
@implementation CPTimeZone : CPObject
{
CPData _data @accessors(property=data, readonly);
CPInteger _secondsFromGMT @accessors(property=secondFromGMT, readonly);
CPString _abbreviation @accessors(property=abbreviation, readonly);
CPString _name @accessors(property=name, readonly);
}
/*! Initialize the default value of the class
*/
+ (void)initialize
{
if (self !== [CPTimeZone class])
return;
knownTimeZoneNames = [
@"America/Halifax",
@"America/Juneau",
@"America/Juneau",
@"America/Argentina/Buenos_Aires",
@"America/Halifax",
@"Asia/Dhaka",
@"America/Sao_Paulo",
@"America/Sao_Paulo",
@"Europe/London",
@"Africa/Harare",
@"America/Chicago",
@"Europe/Paris",
@"Europe/Paris",
@"America/Santiago",
@"America/Santiago",
@"America/Bogota",
@"America/Chicago",
@"Africa/Addis_Ababa",
@"America/New_York",
@"Europe/Istanbul",
@"Europe/Istanbul",
@"America/New_York",
@"GMT",
@"Asia/Dubai",
@"Asia/Hong_Kong",
@"Pacific/Honolulu",
@"Asia/Bangkok",
@"Asia/Tehran",
@"Asia/Calcutta",
@"Asia/Tokyo",
@"Asia/Seoul",
@"America/Denver",
@"Europe/Moscow",
@"Europe/Moscow",
@"America/Denver",
@"Pacific/Auckland",
@"Pacific/Auckland",
@"America/Los_Angeles",
@"America/Lima",
@"Asia/Manila",
@"Asia/Karachi",
@"America/Los_Angeles",
@"Asia/Singapore",
@"UTC",
@"Africa/Lagos",
@"Europe/Lisbon",
@"Europe/Lisbon",
@"Asia/Jakarta"
];
abbreviationDictionary = @{
@"ADT" : @"America/Halifax",
@"AKDT" : @"America/Juneau",
@"AKST" : @"America/Juneau",
@"ART" : @"America/Argentina/Buenos_Aires",
@"AST" : @"America/Halifax",
@"BDT" : @"Asia/Dhaka",
@"BRST" : @"America/Sao_Paulo",
@"BRT" : @"America/Sao_Paulo",
@"BST" : @"Europe/London",
@"CAT" : @"Africa/Harare",
@"CDT" : @"America/Chicago",
@"CEST" : @"Europe/Paris",
@"CET" : @"Europe/Paris",
@"CLST" : @"America/Santiago",
@"CLT" : @"America/Santiago",
@"COT" : @"America/Bogota",
@"CST" : @"America/Chicago",
@"EAT" : @"Africa/Addis_Ababa",
@"EDT" : @"America/New_York",
@"EEST" : @"Europe/Istanbul",
@"EET" : @"Europe/Istanbul",
@"EST" : @"America/New_York",
@"GMT" : @"GMT",
@"GST" : @"Asia/Dubai",
@"HKT" : @"Asia/Hong_Kong",
@"HST" : @"Pacific/Honolulu",
@"ICT" : @"Asia/Bangkok",
@"IRST" : @"Asia/Tehran",
@"IST" : @"Asia/Calcutta",
@"JST" : @"Asia/Tokyo",
@"KST" : @"Asia/Seoul",
@"MDT" : @"America/Denver",
@"MSD" : @"Europe/Moscow",
@"MSK" : @"Europe/Moscow",
@"MST" : @"America/Denver",
@"NZDT" : @"Pacific/Auckland",
@"NZST" : @"Pacific/Auckland",
@"PDT" : @"America/Los_Angeles",
@"PET" : @"America/Lima",
@"PHT" : @"Asia/Manila",
@"PKT" : @"Asia/Karachi",
@"PST" : @"America/Los_Angeles",
@"SGT" : @"Asia/Singapore",
@"UTC" : @"UTC",
@"WAT" : @"Africa/Lagos",
@"WEST" : @"Europe/Lisbon",
@"WET" : @"Europe/Lisbon",
@"WIT" : @"Asia/Jakarta"
};
timeDifferenceFromUTC = @{
@"ADT" : -180,
@"AKDT" : -480,
@"AKST" : -540,
@"ART" : -180,
@"AST" : -240,
@"BDT" : 360,
@"BRST" : -120,
@"BRT" : -180,
@"BST" : 60,
@"CAT" : 120,
@"CDT" : -300,
@"CEST" : 120,
@"CET" : 60,
@"CLST" : -180,
@"CLT" : -240,
@"COT" : -300,
@"CST" : -360,
@"EAT" : 180,
@"EDT" : -240,
@"EEST" : 180,
@"EET" : 120,
@"EST" : -300,
@"GMT" : 0,
@"GST" : 240,
@"HKT" : 480,
@"HST" : -600,
@"ICT" : 420,
@"IRST" : 210,
@"IST" : 330,
@"JST" : 540,
@"KST" : 540,
@"MDT" : -300,
@"MSD" : 240,
@"MSK" : 240,
@"MST" : -420,
@"NZDT" : 900,
@"NZST" : 900,
@"PDT" : -420,
@"PET" : -300,
@"PHT" : 480,
@"PKT" : 300,
@"PST" : -480,
@"SGT" : 480,
@"UTC" : 0,
@"WAT" : -540,
@"WEST" : 60,
@"WET" : 0,
@"WIT" : 540
};
var englishLocalizedName = @{
@"EDT" : [@"Eastern Standard Time", @"EST", @"Eastern Daylight Time", @"EDT", @"Eastern Time", @"ET"],
@"GMT" : [@"GMT", @"GMT", @"GMT", @"GMT", @"GMT", @"GMT"],
@"AST" : [@"Atlantic Standard Time", @"AST", @"Atlantic Daylight Time", @"ADT", @"Atlantic Time", @"AT"],
@"IRST" : [@"Iran Standard Time", @"GMT+03:30", @"Iran Daylight Time", @"GMT+03:30", @"Iran Time", @"Iran Time"],
@"ICT" : [@"Indochina Time", @"GMT+07:00", @"GMT+07:00", @"GMT+07:00", @"Indochina Time", @"Thailand Time"],
@"PET" : [@"Peru Standard Time", @"GMT-05:00", @"Peru Summer Time", @"GMT-05:00", @"Peru Standard Time", @"Peru Time"],
@"KST" : [@"Korean Standard Time", @"GMT+09:00", @"Korean Daylight Time", @"GMT+09:00", @"Korean Standard Time", @"South Korea Time"],
@"PST" : [@"Pacific Standard Time", @"PST", @"Pacific Daylight Time", @"PDT", @"Pacific Time", @"PT"],
@"CDT" : [@"Central Standard Time", @"CST", @"Central Daylight Time", @"CDT", @"Central Time", @"CT"],
@"EEST" : [@"Eastern European Standard Time", @"GMT+02:00", @"Eastern European Summer Time", @"GMT+03:00", @"Eastern European Time", @"Turkey Time"],
@"NZDT" : [@"New Zealand Standard Time", @"GMT+12:00", @"New Zealand Daylight Time", @"GMT+13:00", @"New Zealand Time", @"New Zealand Time (Auckland)"],
@"WEST" : [@"Western European Standard Time", @"GMT", @"Western European Summer Time", @"GMT+01:00", @"Western European Time", @"Portugal Time (Lisbon)"],
@"EAT" : [@"East Africa Time", @"GMT+03:00", @"GMT+03:00", @"GMT+03:00", @"East Africa Time", @"Ethiopia Time"],
@"HKT" : [@"Hong Kong Standard Time", @"GMT+08:00", @"Hong Kong Summer Time", @"GMT+08:00", @"Hong Kong Standard Time", @"Hong Kong SAR China Time"],
@"IST" : [@"India Standard Time", @"GMT+05:30", @"GMT+05:30", @"GMT+05:30", @"India Standard Time", @"India Time"],
@"MDT" : [@"Mountain Standard Time", @"MST", @"Mountain Daylight Time", @"MDT", @"Mountain Time", @"MT"],
@"NZST" : [@"New Zealand Standard Time", @"GMT+12:00", @"New Zealand Daylight Time", @"GMT+13:00", @"New Zealand Time", @"New Zealand Time (Auckland)"],
@"WIT" : [@"Western Indonesia Time", @"GMT+07:00", @"GMT+07:00", @"GMT+07:00", @"Western Indonesia Time", @"Indonesia Time (Jakarta)"],
@"ADT" : [@"Atlantic Standard Time", @"AST", @"Atlantic Daylight Time", @"ADT", @"Atlantic Time", @"AT"],
@"BST" : [@"Greenwich Mean Time", @"GMT", @"British Summer Time", @"GMT+01:00", @"United Kingdom Time", @"United Kingdom Time"],
@"ART" : [@"Argentina Standard Time", @"GMT-03:00", @"Argentina Summer Time", @"GMT-03:00", @"Argentina Standard Time", @"Argentina Time (Buenos Aires)"],
@"CAT" : [@"Central Africa Time", @"GMT+02:00", @"GMT+02:00", @"GMT+02:00", @"Central Africa Time", @"Zimbabwe Time"],
@"GST" : [@"Gulf Standard Time", @"GMT+04:00", @"GMT+04:00", @"GMT+04:00", @"Gulf Standard Time", @"United Arab Emirates Time"],
@"PDT" : [@"Pacific Standard Time", @"PST", @"Pacific Daylight Time", @"PDT", @"Pacific Time", @"PT"],
@"SGT" : [@"Singapore Standard Time", @"GMT+08:00", @"GMT+08:00", @"GMT+08:00", @"Singapore Standard Time", @"Singapore Time"],
@"COT" : [@"Colombia Standard Time", @"GMT-05:00", @"Colombia Summer Time", @"GMT-05:00", @"Colombia Standard Time", @"Colombia Time"],
@"PKT" : [@"Pakistan Standard Time", @"GMT+05:00", @"Pakistan Summer Time", @"GMT+05:00", @"Pakistan Standard Time", @"Pakistan Time"],
@"EET" : [@"Eastern European Standard Time", @"GMT+02:00", @"Eastern European Summer Time", @"GMT+03:00", @"Eastern European Time", @"Turkey Time"],
@"UTC" : [@"GMT", @"GMT", @"GMT", @"GMT", @"GMT", @"GMT"],
@"WAT" : [@"West Africa Standard Time", @"GMT+01:00", @"West Africa Summer Time", @"GMT+01:00", @"West Africa Standard Time", @"Nigeria Time"],
@"EST" : [@"Eastern Standard Time", @"EST", @"Eastern Daylight Time", @"EDT", @"Eastern Time", @"ET"],
@"JST" : [@"Japan Standard Time", @"GMT+09:00", @"Japan Daylight Time", @"GMT+09:00", @"Japan Standard Time", @"Japan Time"],
@"CLST" : [@"Chile Standard Time", @"GMT-04:00", @"Chile Summer Time", @"GMT-04:00", @"Chile Time", @"Chile Time (Santiago)"],
@"CET" : [@"Central European Standard Time", @"GMT+01:00", @"Central European Summer Time", @"GMT+02:00", @"Central European Time", @"France Time"],
@"BDT" : [@"Bangladesh Standard Time", @"GMT+06:00", @"Bangladesh Summer Time", @"GMT+06:00", @"Bangladesh Standard Time", @"Bangladesh Time"],
@"MSK" : [@"Moscow Standard Time", @"GMT+04:00", @"Moscow Summer Time", @"GMT+04:00", @"Moscow Standard Time", @"Russia Time (Moscow)"],
@"AKDT" : [@"Alaska Standard Time", @"AKST", @"Alaska Daylight Time", @"AKDT", @"Alaska Time", @"AKT"],
@"CLT" : [@"Chile Standard Time", @"GMT-04:00", @"Chile Summer Time", @"GMT-04:00", @"Chile Time", @"Chile Time (Santiago)"],
@"AKST" : [@"Alaska Standard Time", @"AKST", @"Alaska Daylight Time", @"AKDT", @"Alaska Time", @"AKT"],
@"BRST" : [@"Brasilia Standard Time", @"GMT-03:00", @"Brasilia Summer Time", @"GMT-03:00", @"Brasilia Time", @"Brazil Time (Sao Paulo)"],
@"BRT" : [@"Brasilia Standard Time", @"GMT-03:00", @"Brasilia Summer Time", @"GMT-03:00", @"Brasilia Time", @"Brazil Time (Sao Paulo)"],
@"CEST" : [@"Central European Standard Time", @"GMT+01:00", @"Central European Summer Time", @"GMT+02:00", @"Central European Time", @"France Time"],
@"CST" : [@"Central Standard Time", @"CST", @"Central Daylight Time", @"CDT", @"Central Time", @"CT"],
@"HST" : [@"Hawaii-Aleutian Standard Time", @"HST", @"Hawaii-Aleutian Daylight Time", @"HDT", @"Hawaii-Aleutian Standard Time", @"HST"],
@"MSD" : [@"Moscow Standard Time", @"GMT+04:00", @"Moscow Summer Time", @"GMT+04:00", @"Moscow Standard Time", @"Russia Time (Moscow)"],
@"MST" : [@"Mountain Standard Time", @"MST", @"Mountain Daylight Time", @"MDT", @"Mountain Time", @"MT"],
@"PHT" : [@"Philippine Standard Time", @"GMT+08:00", @"Philippine Summer Time", @"GMT+08:00", @"Philippine Standard Time", @"Philippines Time"],
@"WET" : [@"Western European Standard Time", @"GMT", @"Western European Summer Time", @"GMT+01:00", @"Western European Time", @"Portugal Time (Lisbon)"]
};
var date = [CPDate date],
abbreviation = String(String(date).split("(")[1]).split(")")[0];
localTimeZone = [self timeZoneWithAbbreviation:abbreviation];
systemTimeZone = [self timeZoneWithAbbreviation:abbreviation];
defaultTimeZone = [self timeZoneWithAbbreviation:abbreviation];
localizedName = @{
@"en" : englishLocalizedName,
@"fr" : @{},
@"de" : @{},
@"es" : @{}
};
timeZoneDataVersion = nil;
}
#pragma mark -
#pragma mark Class constructor
/*! Returns a time zone from the given abbreviation.
Returns nil if the given abbreviation doesn't match with any abbreviations
@param abbreviation the given abreviation
@return a new instance of CPTimeZone
*/
+ (id)timeZoneWithAbbreviation:(CPString)abbreviation
{
if (![abbreviationDictionary containsKey:abbreviation])
return nil;
return [[CPTimeZone alloc] _initWithName:[abbreviationDictionary valueForKey:abbreviation] abbreviation:abbreviation];
}
/*! Return a time zone from the given timeZone name
Returns nil if the given timeZone name doesn't match with any abbreviations
Raises an exception if tzName is nil
@param tzName the timeZone name
@return a new instance of CPTimeZone
*/
+ (id)timeZoneWithName:(CPString)tzName
{
return [[CPTimeZone alloc] initWithName:tzName];
}
/*! Return a time zone from the given timeZone name and data
Returns nil if the given timeZone name doesn't match with any abbreviations
Raises an exception if tzName is nil
@param tzName the timeZone name
@param data the data
@return a new instance of CPTimeZone
*/
+ (id)timeZoneWithName:(CPString)tzName data:(CPData)data
{
return [[CPTimeZone alloc] initWithName:tzName data:data];
}
/*! Return a time zone from the given seconds
Returns nil if the number of seconds doesn't match with any offset
@param seconds the number of seconds
@return a new instance of CPTimeZone
*/
+ (id)timeZoneForSecondsFromGMT:(CPInteger)seconds
{
var minutes = seconds / 60,
keys = [timeDifferenceFromUTC keyEnumerator],
key,
abbreviation = nil;
while (key = [keys nextObject])
{
var value = [timeDifferenceFromUTC valueForKey:key];
if (value == minutes)
{
abbreviation = key;
break;
}
}
if (!abbreviation)
return nil;
return [self timeZoneWithAbbreviation:abbreviation];
}
/*! @ignore
*/
+ (id)_timeZoneFromString:(CPString)aTimeZoneString style:(NSTimeZoneNameStyle)style locale:(CPLocale)_locale
{
if ([abbreviationDictionary containsKey:aTimeZoneString])
return [self timeZoneWithAbbreviation:aTimeZoneString];
var dict = [localizedName valueForKey:[_locale objectForKey:CPLocaleLanguageCode]];
keys = [dict keyEnumerator],
key;
while (key = [keys nextObject])
{
var value = [[dict valueForKey:key] objectAtIndex:style];
if ([value isEqualToString:aTimeZoneString])
return [self timeZoneWithAbbreviation:key];
}
return nil;
}
/*! @ignore
*/
+ (CPArray)_namesForStyle:(NSTimeZoneNameStyle)style locale:(CPLocale)aLocale
{
var array = [CPArray array],
dict = [localizedName valueForKey:[aLocale objectForKey:CPLocaleLanguageCode]];
keys = [dict keyEnumerator],
key;
while (key = [keys nextObject])
[array addObject:[[dict valueForKey:key] objectAtIndex:style]];
return array;
}
#pragma mark -
#pragma mark Class accessors
/*! Return the timeZoneDataVersion (not yet implemented)
*/
+ (CPString)timeZoneDataVersion
{
// TODO : don't know what to do ^^
return timeZoneDataVersion;
}
/*! Return the localTimeZone
*/
+ (CPTimeZone)localTimeZone
{
return localTimeZone;
}
/*! Return the defaultTimeZone
*/
+ (CPTimeZone)defaultTimeZone
{
return defaultTimeZone;
}
/*! Set the defaultTimeZone
@param aTimeZone the defaultTimeZone
*/
+ (void)setDefaultTimeZone:(CPTimeZone)aTimeZone
{
defaultTimeZone = aTimeZone;
}
/*! Reset the systemTimeZone
This will send the notification CPSystemTimeZoneDidChangeNotification
*/
+ (void)resetSystemTimeZone
{
var date = [CPDate date],
abbreviation = String(String(date).split("(")[1]).split(")")[0];
systemTimeZone = [self timeZoneWithAbbreviation:abbreviation];
[[CPNotification defaultCenter] postNotificationName:CPSystemTimeZoneDidChangeNotification object:systemTimeZone];
}
/*! Return the systemTimeZone
*/
+ (CPTimeZone)systemTimeZone
{
return systemTimeZone;
}
/*! Return the abbreviationDictionary
*/
+ (CPDictionary)abbreviationDictionary
{
return abbreviationDictionary;
}
/*! Set the abbreviationDictionary
@param dict
*/
+ (void)setAbbreviationDictionary:(CPDictionary)dict
{
abbreviationDictionary = dict;
}
/*! Return the knownTimeZoneNames
*/
+ (CPArray)knownTimeZoneNames
{
return knownTimeZoneNames;
}
#pragma mark -
#pragma mark Consructors
/*! Init a new time zone with the given time zone name and abbreviation
Returns nil if tzName doesn't match with any timeZoneNames or if abbreviation is nil
Raises an exception if tzName is nil
@param tzName the timeZone name
@param abbreviation the abbreviation
@return a new timeZone
*/
- (id)_initWithName:(CPString)tzName abbreviation:(CPString)abbreviation
{
if (!tzName)
[CPException raise:CPInvalidArgumentException reason:"Invalid value provided for tzName"];
if (![knownTimeZoneNames containsObject:tzName] || !abbreviation)
return nil;
if (self = [super init])
{
_name = tzName;
_abbreviation = abbreviation;
}
return self;
}
/*! Init a new time zone from the given timeZone name
Returns nil if the given timeZone name doesn't match with any abbreviations
Raises an exception if tzName is nil
@param tzName the timeZone name
@return a new instance of CPTimeZone
*/
- (id)initWithName:(CPString)tzName
{
if (!tzName)
[CPException raise:CPInvalidArgumentException reason:"Invalid value provided for tzName"];
if (![knownTimeZoneNames containsObject:tzName])
return nil;
if (self = [super init])
{
_name = tzName;
var keys = [abbreviationDictionary keyEnumerator],
key;
while (key = [keys nextObject])
{
var value = [abbreviationDictionary valueForKey:key];
if ([value isEqualToString:_name])
{
_abbreviation = key;
break;
}
}
}
return self;
}
/*! Return a time zone from the given timeZone name and data
Returns nil if the given timeZone name doesn't match with any abbreviations
Raises an exception if tzName is nil
@param tzName the timeZone name
@param data the data
@return a new instance of CPTimeZone
*/
- (id)initWithName:(CPString)tzName data:(CPData)data
{
if (self = [self initWithName:tzName])
{
_data = data;
}
return self;
}
#pragma mark -
#pragma mark Methods for CPDate
/*! Returns the abbreviation from a date
Returns nil if the date is nil
@return the abbreviation
*/
- (CPString)abbreviationForDate:(CPDate)date
{
if (!date)
return nil;
return String(String(date).split("(")[1]).split(")")[0];
}
/*! Returns the number of seconds from GMT for the given date
Returns nil if the date is nil
@param date
@return the number of seconds
*/
- (CPInteger)secondsFromGMTForDate:(CPDate)date
{
if (!date)
return nil;
var abbreviation = String(String(date).split("(")[1]).split(")")[0];
return [timeDifferenceFromUTC valueForKey:abbreviation] * 60;
}
/*! Returns the number of seconds from GMT
@return the number of seconds
*/
- (CPInteger)secondsFromGMT
{
return [timeDifferenceFromUTC valueForKey:_abbreviation] * 60;
}
#pragma mark -
#pragma mark Compars methods
/*! Returns a bool to compare tow timeZones.
This is made by the compare of the name and the data of the timeZones
@return a bool
*/
- (BOOL)isEqualToTimeZone:(CPTimeZone)aTimeZone
{
return [[aTimeZone name] isEqualToString:_name] && [aTimeZone data] == _data
}
#pragma mark -
#pragma mark Description
/*! Returns the description of the timeZone
The pattern of the description is : 'name of the timeZone' ('abbreviation of the timeZone') offset 'the timeDifferenceFromGMT'
@return the description
*/
- (CPString)description
{
return [CPString stringWithFormat:@"%s (%s) offset %i", _name, _abbreviation, [self secondsFromGMT]];
}
#pragma mark -
#pragma mark Localized methods
/*! Return a localized string from the given style and locale
@param style the style
@param locale the locale
@return a string
*/
- (CPString)localizedName:(NSTimeZoneNameStyle)style locale:(CPLocale)locale
{
if (style > 5)
return nil;
return [[[localizedName valueForKey:[locale objectForKey:CPLocaleLanguageCode]] valueForKey:_abbreviation] objectAtIndex:style];
}
@end
+1
View File
@@ -69,6 +69,7 @@
@import "CPSortDescriptor.j"
@import "CPString.j"
@import "CPTimer.j"
@import "CPTimeZone.j"
@import "CPUndoManager.j"
@import "CPURL.j"
@import "CPURLConnection.j"
File diff suppressed because it is too large Load Diff
+298
View File
@@ -0,0 +1,298 @@
/* CPTimeZoneTest.j
* Foundation
*
* Created by Alexandre Wilhelm
* Copyright 2012 <alexandre.wilhelmfr@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <Foundation/Foundation.j>
@import <OJUnit/OJTestCase.j>
@implementation CPTimeZoneTest : OJTestCase
{
CPLocale _locale;
CPData _data;
CPDate _date;
}
- (void)setUp
{
_locale = [[CPLocale alloc] initWithLocaleIdentifier:@"en_US"];
_data = [CPData dataWithRawString:@"Data with string"];
_date = [[CPDate alloc] initWithString:@"2011-10-05 16:34:38 +0900"];
}
- (void)tearDown
{
}
- (void)testTimeZoneWithAbbreviation
{
var timeZone = [CPTimeZone timeZoneWithAbbreviation:@"PDT"];
[self assert:[timeZone name] equals:@"America/Los_Angeles"];
[self assert:[timeZone abbreviation] equals:@"PDT"];
[self assert:[timeZone secondsFromGMT] equals:(-420 * 60)];
[self assert:[timeZone description] equals:@"America/Los_Angeles (PDT) offset -25200"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleStandard locale:_locale] equals:@"Pacific Standard Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortStandard locale:_locale] equals:@"PST"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleDaylightSaving locale:_locale] equals:@"Pacific Daylight Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortDaylightSaving locale:_locale] equals:@"PDT"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleGeneric locale:_locale] equals:@"Pacific Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortGeneric locale:_locale] equals:@"PT"];
}
- (void)testTimeZoneWithWrongAbbreviation
{
var timeZone = [CPTimeZone timeZoneWithAbbreviation:@"PDTezdez"];
[self assert:timeZone equals:nil];
}
- (void)testTimeZoneWithName
{
var timeZone = [CPTimeZone timeZoneWithName:@"America/Los_Angeles"];
[self assert:[timeZone name] equals:@"America/Los_Angeles"];
[self assert:[timeZone abbreviation] equals:@"PDT"];
[self assert:[timeZone secondsFromGMT] equals:(-420 * 60)];
[self assert:[timeZone description] equals:@"America/Los_Angeles (PDT) offset -25200"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleStandard locale:_locale] equals:@"Pacific Standard Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortStandard locale:_locale] equals:@"PST"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleDaylightSaving locale:_locale] equals:@"Pacific Daylight Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortDaylightSaving locale:_locale] equals:@"PDT"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleGeneric locale:_locale] equals:@"Pacific Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortGeneric locale:_locale] equals:@"PT"];
}
- (void)testTimeZoneWithWrongName
{
var timeZone = [CPTimeZone timeZoneWithName:@"America/Los_Angelesezdez"];
[self assert:timeZone equals:nil];
}
- (void)testexceptionTimeZoneWithNilNameWithData
{
try
{
var timeZone = [CPTimeZone timeZoneWithName:nil];
[self fail:"Invalid value provided for tzName"];
}
catch (e)
{
}
}
- (void)testTimeZoneWithNameWithData
{
var timeZone = [CPTimeZone timeZoneWithName:@"America/Los_Angeles" data:_data];
[self assert:[timeZone name] equals:@"America/Los_Angeles"];
[self assert:[timeZone abbreviation] equals:@"PDT"];
[self assert:[timeZone secondsFromGMT] equals:(-420 * 60)];
[self assert:[timeZone data] equals:_data];
[self assert:[timeZone description] equals:@"America/Los_Angeles (PDT) offset -25200"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleStandard locale:_locale] equals:@"Pacific Standard Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortStandard locale:_locale] equals:@"PST"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleDaylightSaving locale:_locale] equals:@"Pacific Daylight Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortDaylightSaving locale:_locale] equals:@"PDT"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleGeneric locale:_locale] equals:@"Pacific Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortGeneric locale:_locale] equals:@"PT"];
}
- (void)testTimeZoneWithWrongNameWithData
{
var timeZone = [CPTimeZone timeZoneWithName:@"America/Los_Angelesezdez" data:_data];
[self assert:timeZone equals:nil];
}
- (void)testexceptionTimeZoneWithNilNameWithData
{
try
{
var timeZone = [CPTimeZone timeZoneWithName:nil data:_data];
[self fail:"Invalid value provided for tzName"];
}
catch (e)
{
}
}
- (void)testTimeZoneWithSecondsFromGMT
{
var timeZone = [CPTimeZone timeZoneForSecondsFromGMT:(-600 * 60)];
[self assert:[timeZone name] equals:@"Pacific/Honolulu"];
[self assert:[timeZone abbreviation] equals:@"HST"];
[self assert:[timeZone secondsFromGMT] equals:(-600 * 60)];
[self assert:[timeZone description] equals:@"Pacific/Honolulu (HST) offset -36000"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleStandard locale:_locale] equals:@"Hawaii-Aleutian Standard Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortStandard locale:_locale] equals:@"HST"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleDaylightSaving locale:_locale] equals:@"Hawaii-Aleutian Daylight Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortDaylightSaving locale:_locale] equals:@"HDT"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleGeneric locale:_locale] equals:@"Hawaii-Aleutian Standard Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortGeneric locale:_locale] equals:@"HST"];
}
- (void)testTimeZoneWithWrongSecondsFromGMT
{
var timeZone = [CPTimeZone timeZoneForSecondsFromGMT:(-421 * 60)];
[self assert:timeZone equals:nil];
}
- (void)testInitTimeZoneWithName
{
var timeZone = [[CPTimeZone alloc] initWithName:@"America/Los_Angeles"];
[self assert:[timeZone name] equals:@"America/Los_Angeles"];
[self assert:[timeZone abbreviation] equals:@"PDT"];
[self assert:[timeZone secondsFromGMT] equals:(-420 * 60)];
[self assert:[timeZone description] equals:@"America/Los_Angeles (PDT) offset -25200"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleStandard locale:_locale] equals:@"Pacific Standard Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortStandard locale:_locale] equals:@"PST"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleDaylightSaving locale:_locale] equals:@"Pacific Daylight Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortDaylightSaving locale:_locale] equals:@"PDT"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleGeneric locale:_locale] equals:@"Pacific Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortGeneric locale:_locale] equals:@"PT"];
}
- (void)testInitTimeZoneWithWrongName
{
var timeZone = [[CPTimeZone alloc] initWithName:@"America/Los_Angelesezdez"];
[self assert:timeZone equals:nil];
}
- (void)testexceptionInitTimeZoneWithNilName
{
try
{
var timeZone = [[CPTimeZone alloc] initWithName:nil];
[self fail:"Invalid value provided for tzName"];
}
catch (e)
{
}
}
- (void)testInitTimeZoneWithNameWithData
{
var timeZone = [[CPTimeZone alloc] initWithName:@"America/Los_Angeles" data:_data];
[self assert:[timeZone name] equals:@"America/Los_Angeles"];
[self assert:[timeZone abbreviation] equals:@"PDT"];
[self assert:[timeZone secondsFromGMT] equals:(-420 * 60)];
[self assert:[timeZone data] equals:_data];
[self assert:[timeZone description] equals:@"America/Los_Angeles (PDT) offset -25200"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleStandard locale:_locale] equals:@"Pacific Standard Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortStandard locale:_locale] equals:@"PST"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleDaylightSaving locale:_locale] equals:@"Pacific Daylight Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortDaylightSaving locale:_locale] equals:@"PDT"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleGeneric locale:_locale] equals:@"Pacific Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortGeneric locale:_locale] equals:@"PT"];
}
- (void)testInitTimeZoneWithWrongNameWithData
{
var timeZone = [[CPTimeZone alloc] initWithName:@"America/Los_Angelesezdez" data:_data];
[self assert:timeZone equals:nil];
}
- (void)testexceptionInitTimeZoneWithNilNameWithData
{
try
{
var timeZone = [[CPTimeZone alloc] initWithName:nil data:_data];
[self fail:"Invalid value provided for tzName"];
}
catch (e)
{
}
}
- (void)testAbbreviationWithDate
{
var timeZone = [CPTimeZone localTimeZone],
abbreviation = [timeZone abbreviationForDate:_date];
[self assert:abbreviation equals:@"PDT"];
}
- (void)testAbbreviationWithNilDate
{
var timeZone = [CPTimeZone localTimeZone],
abbreviation = [timeZone abbreviationForDate:nil];
[self assert:abbreviation equals:nil];
}
- (void)testSecondsFromGMTForDate
{
var timeZone = [CPTimeZone localTimeZone],
seconds = [timeZone secondsFromGMTForDate:_date];
[self assert:seconds equals:-25200];
}
- (void)testSecondsFromGMTForDateWithNilDate
{
var timeZone = [CPTimeZone localTimeZone],
seconds = [timeZone secondsFromGMTForDate:nil];
[self assert:seconds equals:nil];
}
- (void)testSecondsFromGMT
{
var timeZone = [[CPTimeZone alloc] initWithName:@"America/Los_Angeles"];
[self assert:[timeZone secondsFromGMT] equals:(-420 * 60)];
}
- (void)testDescription
{
var timeZone = [[CPTimeZone alloc] initWithName:@"America/Los_Angeles"];
[self assert:[timeZone description] equals:@"America/Los_Angeles (PDT) offset -25200"];
}
- (void)testLocalizedName
{
var timeZone = [[CPTimeZone alloc] initWithName:@"America/Los_Angeles"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleStandard locale:_locale] equals:@"Pacific Standard Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortStandard locale:_locale] equals:@"PST"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleDaylightSaving locale:_locale] equals:@"Pacific Daylight Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortDaylightSaving locale:_locale] equals:@"PDT"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleGeneric locale:_locale] equals:@"Pacific Time"];
[self assert:[timeZone localizedName:CPTimeZoneNameStyleShortGeneric locale:_locale] equals:@"PT"];
}
- (void)testEqualTrueToTimeZone
{
var timeZone1 = [[CPTimeZone alloc] initWithName:@"America/Los_Angeles"],
timeZone2 = [[CPTimeZone alloc] initWithName:@"America/Los_Angeles"];
[self assert:[timeZone1 isEqualToTimeZone:timeZone2] equals:YES];
}
- (void)testEqualFalseToTimeZone
{
var timeZone1 = [[CPTimeZone alloc] initWithName:@"America/Los_Angeles"],
timeZone2 = [[CPTimeZone alloc] initWithName:@"Pacific/Honolulu"];
[self assert:[timeZone1 isEqualToTimeZone:timeZone2] equals:NO];
}
@end
@@ -0,0 +1,43 @@
/*
* AppController.j
* CPDateFormatterTest
*
* Created by You on April 9, 2013.
* Copyright 2013, Your Company All rights reserved.
*/
@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
@implementation AppController : CPObject
{
@outlet CPWindow theWindow;
@outlet CPDatePicker datePicker;
@outlet CPTextField labelDateFormatter;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
// This is called when the application is done loading.
}
- (void)awakeFromCib
{
// This is called when the cib is done loading.
// You can implement this method on any object instantiated from a Cib.
// It's a useful hook for setting up current UI values, and other things.
// In this case, we want the window from Cib to become our full browser window
[theWindow setFullPlatformWindow:YES];
[datePicker setTimeZone:[CPTimeZone timeZoneForSecondsFromGMT:0]];
[datePicker setDateValue:[CPDate date]];
}
- (@action)datePickerAction:(id)sender
{
console.log([sender dateValue]);
[labelDateFormatter setStringValue:[[sender formatter] stringFromDate:[sender dateValue]]];
}
@end
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Main cib file base name</key>
<string>MainMenu.cib</string>
<key>CPBundleName</key>
<string>CPDateFormatterTest</string>
</dict>
</plist>
+94
View File
@@ -0,0 +1,94 @@
/*
* Jakefile
* CPDateFormatterTest
*
* Created by You on April 9, 2013.
* Copyright 2013, Your Company All rights reserved.
*/
var ENV = require("system").env,
FILE = require("file"),
JAKE = require("jake"),
task = JAKE.task,
FileList = JAKE.FileList,
app = require("cappuccino/jake").app,
configuration = ENV["CONFIG"] || ENV["CONFIGURATION"] || ENV["c"] || "Debug",
OS = require("os");
app ("CPDateFormatterTest", function(task)
{
task.setBuildIntermediatesPath(FILE.join("Build", "CPDateFormatterTest.build", configuration));
task.setBuildPath(FILE.join("Build", configuration));
task.setProductName("CPDateFormatterTest");
task.setIdentifier("com.yourcompany.CPDateFormatterTest");
task.setVersion("1.0");
task.setAuthor("Your Company");
task.setEmail("feedback @nospam@ yourcompany.com");
task.setSummary("CPDateFormatterTest");
task.setSources((new FileList("**/*.j")).exclude(FILE.join("Build", "**")));
task.setResources(new FileList("Resources/**"));
task.setIndexFilePath("index.html");
task.setInfoPlistPath("Info.plist");
task.setNib2CibFlags("-R Resources/");
if (configuration === "Debug")
task.setCompilerFlags("-DDEBUG -g");
else
task.setCompilerFlags("-O");
});
task ("default", ["CPDateFormatterTest"], function()
{
printResults(configuration);
});
task ("build", ["default"]);
task ("debug", function()
{
ENV["CONFIGURATION"] = "Debug";
JAKE.subjake(["."], "build", ENV);
});
task ("release", function()
{
ENV["CONFIGURATION"] = "Release";
JAKE.subjake(["."], "build", ENV);
});
task ("run", ["debug"], function()
{
OS.system(["open", FILE.join("Build", "Debug", "CPDateFormatterTest", "index.html")]);
});
task ("run-release", ["release"], function()
{
OS.system(["open", FILE.join("Build", "Release", "CPDateFormatterTest", "index.html")]);
});
task ("deploy", ["release"], function()
{
FILE.mkdirs(FILE.join("Build", "Deployment", "CPDateFormatterTest"));
OS.system(["press", "-f", FILE.join("Build", "Release", "CPDateFormatterTest"), FILE.join("Build", "Deployment", "CPDateFormatterTest")]);
printResults("Deployment")
});
task ("desktop", ["release"], function()
{
FILE.mkdirs(FILE.join("Build", "Desktop", "CPDateFormatterTest"));
require("cappuccino/nativehost").buildNativeHost(FILE.join("Build", "Release", "CPDateFormatterTest"), FILE.join("Build", "Desktop", "CPDateFormatterTest", "CPDateFormatterTest.app"));
printResults("Desktop")
});
task ("run-desktop", ["desktop"], function()
{
OS.system([FILE.join("Build", "Desktop", "CPDateFormatterTest", "CPDateFormatterTest.app", "Contents", "MacOS", "NativeHost"), "-i"]);
});
function printResults(configuration)
{
print("----------------------------");
print(configuration+" app built at path: "+FILE.join("Build", configuration, "CPDateFormatterTest"));
print("----------------------------");
}
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

@@ -0,0 +1,112 @@
<!DOCTYPE html>
<html lang="en">
<!--
index-debug.html
CPDateFormatterTest
Created by You on April 9, 2013.
Copyright 2013, Your Company All rights reserved.
-->
<head>
<meta charset="utf-8">
<!--[if lte IE 8]>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7, chrome=1">
<![endif]-->
<!--[if gte IE 9]>
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<![endif]-->
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon" href="Resources/icon.png">
<link rel="apple-touch-startup-image" href="Resources/default.png">
<title>CPDateFormatterTest</title>
<script type="text/javascript">
OBJJ_MAIN_FILE = "main.j";
OBJJ_INCLUDE_PATHS = ["Frameworks/Debug", "Frameworks"];
</script>
<script type="text/javascript" src="Frameworks/Debug/Objective-J/Objective-J.js" charset="UTF-8"></script>
<script type="text/javascript">
objj_msgSend_reset();
// DEBUG OPTIONS:
// Uncomment to enable printing of backtraces on exceptions:
//objj_msgSend_decorate(objj_backtrace_decorator);
// Uncomment to supress exceptions that take place inside a message
//objj_msgSend_decorate(objj_supress_exceptions_decorator)
// Uncomment to enable runtime type checking:
//objj_msgSend_decorate(objj_typecheck_decorator);
// Uncomment (along with both above) to print backtraces on type check errors:
//objj_typecheck_prints_backtrace = true;
// Uncomment to disable the default logger (CPLogConsole if window.console exists, CPLogPopup otherwise):
//CPLogUnregister(CPLogDefault);
// Uncomment to enable a specific logger:
//CPLogRegister(CPLogConsole);
//CPLogRegister(CPLogPopup);
// Tag view DOM elements with a "data-cappuccino-view" attribute that contains
// the class name of the view that created them. Comment this or set to false to disable.
appkit_tag_dom_elements = true;
</script>
<style type="text/css">
body{margin:0; padding:0;}
#container {position: absolute; top:50%; left:50%;}
#content {width:800px; text-align:center; margin-left: -400px; height:50px; margin-top:-25px; line-height: 50px;}
#content {font-family: "Helvetica", "Arial", sans-serif; font-size: 18px; color: black; text-shadow: 0px 1px 0px white; }
#loadgraphic {margin-right: 0.2em; margin-bottom:-2px;}
</style>
<!--[if lt IE 7]>
<STYLE type="text/css">
#container { position: relative; top: 50%; }
#content { position: relative;}
</STYLE>
<![endif]-->
</head>
<body style="">
<div id="cappuccino-body">
<div id="loadingcontainer" style="background-color: #eeeeee; overflow:hidden; width:100%; height:100%; position: absolute; top: 0; left: 0;">
<script type="text/javascript">
document.write("<div id='container'><p id='content'>" +
"<img id='loadgraphic' width='16' height='16' src='Resources/spinner.gif' /> " +
"Loading CPDateFormatterTest...</p></div>");
</script>
<noscript>
<div id="container">
<div style="width: 440px; padding: 10px 25px 20px 25px; font-family: sans-serif; background-color: #ffffff; position: relative; left: -245px; top: -120px; text-align: center; -moz-border-radius: 20px; -webkit-border-radius: 20px; color: #555555">
<p style="line-height: 1.4em;">JavaScript is required for this site to work correctly but is either disabled or not supported by your browser.</p>
<p style="font-size:120%; padding:10px;"><a href="http://cappuccino-project.org/noscript">Show me how to enable JavaScript</a></p>
<p style="font-size:80%;">You may want to upgrade to a newer browser while you're at it:</p>
<ul style="margin:0;padding:0; text-align: center; font-size:80%;" >
<li style="display: inline;"><a href="http://www.apple.com/safari/download/">Safari</a></li>
<li style="display: inline;"><a href="http://www.mozilla.com/en-US/firefox/">Firefox</a></li>
<li style="display: inline;"><a href="http://www.google.com/chrome/">Chrome</a></li>
<li style="display: inline;"><a href="http://www.opera.com/download/">Opera</a></li>
<li style="display: inline;"><a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx">Internet Explorer</a></li>
</ul>
</div>
</div>
</noscript>
</div>
</div>
</body>
</html>
@@ -0,0 +1,82 @@
<!DOCTYPE html>
<html lang="en">
<!--
index.html
CPDateFormatterTest
Created by You on April 9, 2013.
Copyright 2013, Your Company All rights reserved.
-->
<head>
<meta charset="utf-8">
<!--[if lte IE 8]>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7, chrome=1">
<![endif]-->
<!--[if gte IE 9]>
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<![endif]-->
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon" href="Resources/icon.png">
<link rel="apple-touch-startup-image" href="Resources/default.png">
<title>CPDateFormatterTest</title>
<script type="text/javascript">
OBJJ_MAIN_FILE = "main.j";
</script>
<script type="text/javascript" src="Frameworks/Objective-J/Objective-J.js" charset="UTF-8"></script>
<style type="text/css">
body{margin:0; padding:0;}
#container {position: absolute; top:50%; left:50%;}
#content {width:800px; text-align:center; margin-left: -400px; height:50px; margin-top:-25px; line-height: 50px;}
#content {font-family: "Helvetica", "Arial", sans-serif; font-size: 18px; color: black; text-shadow: 0px 1px 0px white; }
#loadgraphic {margin-right: 0.2em; margin-bottom:-2px;}
</style>
<!--[if lt IE 7]>
<STYLE type="text/css">
#container { position: relative; top: 50%; }
#content { position: relative;}
</STYLE>
<![endif]-->
</head>
<body style="">
<div id="cappuccino-body">
<div id="loadingcontainer" style="background-color: #eeeeee; overflow:hidden; width:100%; height:100%; position: absolute; top: 0; left: 0;">
<script type="text/javascript">
document.write("<div id='container'><p id='content'>" +
"<img id='loadgraphic' width='16' height='16' src='Resources/spinner.gif' /> " +
"Loading CPDateFormatterTest...</p></div>");
</script>
<noscript>
<div id="container">
<div style="width: 440px; padding: 10px 25px 20px 25px; font-family: sans-serif; background-color: #ffffff; position: relative; left: -245px; top: -120px; text-align: center; -moz-border-radius: 20px; -webkit-border-radius: 20px; color: #555555">
<p style="line-height: 1.4em;">JavaScript is required for this site to work correctly but is either disabled or not supported by your browser.</p>
<p style="font-size:120%; padding:10px;"><a href="http://cappuccino-project.org/noscript">Show me how to enable JavaScript</a></p>
<p style="font-size:80%;">You may want to upgrade to a newer browser while you're at it:</p>
<ul style="margin:0;padding:0; text-align: center; font-size:80%;" >
<li style="display: inline;"><a href="http://www.apple.com/safari/download/">Safari</a></li>
<li style="display: inline;"><a href="http://www.mozilla.com/en-US/firefox/">Firefox</a></li>
<li style="display: inline;"><a href="http://www.google.com/chrome/">Chrome</a></li>
<li style="display: inline;"><a href="http://www.opera.com/download/">Opera</a></li>
<li style="display: inline;"><a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx">Internet Explorer</a></li>
</ul>
</div>
</div>
</noscript>
</div>
</div>
</body>
</html>
+18
View File
@@ -0,0 +1,18 @@
/*
* AppController.j
* CPDateFormatterTest
*
* Created by You on April 9, 2013.
* Copyright 2013, Your Company All rights reserved.
*/
@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
@import "AppController.j"
function main(args, namedArgs)
{
CPApplicationMain(args, namedArgs);
}
File diff suppressed because one or more lines are too long
+22 -1
View File
@@ -22,6 +22,10 @@
@import <Foundation/CPDateFormatter.j>
@global CPDateFormatterBehavior10_0
@global CPDateFormatterBehavior10_4
@global CPDateFormatterMediumStyle
@implementation CPDateFormatter (CPCoding)
- (id)NS_initWithCoder:(CPCoder)aCoder
@@ -30,7 +34,24 @@
if (self)
{
_dateStyle = CPDateFormatterShortStyle;
var attributes = [aCoder decodeObjectForKey:@"NS.attributes"];
_dateStyle = [attributes valueForKey:@"dateStyle"];
_timeStyle = [attributes valueForKey:@"timeStyle"];
_formatterBehavior = [attributes valueForKey:@"formatterBehavior"];
if ([attributes containsKey:@"doesRelativeDateFormatting"])
_doesRelativeDateFormatting = [attributes valueForKey:@"doesRelativeDateFormatting"];
_dateFormat = [aCoder decodeObjectForKey:@"NS.format"];
_allowNaturalLanguage = [aCoder decodeBoolForKey:@"NS.natural"];
if (_formatterBehavior == CPDateFormatterBehavior10_0)
{
_formatterBehavior = CPDateFormatterBehavior10_4;
_timeStyle = CPDateFormatterMediumStyle;
_dateStyle = CPDateFormatterMediumStyle;
}
}
return self;
+14 -9
View File
@@ -53,6 +53,7 @@ var NSDatePickerDefaultSize = 22,
_dateValue = [cell objectValue];
_backgroundColor = [cell backgroundColor];
_drawsBackground = [cell drawsBackground];
_formatter = [cell formatter];
[self setBezeled:[cell isBezeled]];
[self setBordered:[cell isBordered]];
@@ -172,15 +173,16 @@ var NSDatePickerDefaultSize = 22,
@implementation NSDatePickerCell : NSCell
{
BOOL _drawsBackground @accessors(getter=drawsBackground);
CPDate _minDate @accessors(getter=minDate);
CPDate _maxDate @accessors(getter=maxDate);
CPInteger _datePickerMode @accessors(getter=datePickerMode);
CPInteger _datePickerElements @accessors(getter=datePickerElements);
CPinteger _datePickerType @accessors(getter=datePickerType);
double _timeInterval @accessors(getter=timeInterval);
CPColor _textColor @accessors(getter=textColor);
CPColor _backgroundColor @accessors(getter=backgroundColor);
BOOL _drawsBackground @accessors(getter=drawsBackground);
CPDate _minDate @accessors(getter=minDate);
CPDate _maxDate @accessors(getter=maxDate);
CPDateFormatter _formatter @accessors(getter=formatter);
CPInteger _datePickerMode @accessors(getter=datePickerMode);
CPInteger _datePickerElements @accessors(getter=datePickerElements);
CPinteger _datePickerType @accessors(getter=datePickerType);
double _timeInterval @accessors(getter=timeInterval);
CPColor _textColor @accessors(getter=textColor);
CPColor _backgroundColor @accessors(getter=backgroundColor);
}
- (id)initWithCoder:(CPCoder)aCoder
@@ -205,6 +207,9 @@ var NSDatePickerDefaultSize = 22,
_backgroundColor = [aCoder decodeObjectForKey:@"NSBackgroundColor"];
_isBordered = _isBezeled;
if ([aCoder containsValueForKey:@"NSFormatter"])
_formatter = [aCoder decodeObjectForKey:@"NSFormatter"];
if ([aCoder containsValueForKey:@"NSDrawsBackground"])
_drawsBackground = [aCoder decodeBoolForKey:@"NSDrawsBackground"];
else
+5 -1
View File
@@ -33,7 +33,11 @@
- (id)initWithCoder:(CPCoder)aCoder
{
return [CPDictionary dictionaryWithObjects:[aCoder decodeObjectForKey:@"NS.objects"] forKeys:[aCoder decodeObjectForKey:@"NS.keys"]];
if ([aCoder containsValueForKey:@"NS.objects"])
return [CPDictionary dictionaryWithObjects:[aCoder decodeObjectForKey:@"NS.objects"] forKeys:[aCoder decodeObjectForKey:@"NS.keys"]];
if ([aCoder containsValueForKey:@"dict.values"])
return [CPDictionary dictionaryWithObjects:[aCoder decodeObjectForKey:@"dict.values"] forKeys:[aCoder decodeObjectForKey:@"dict.sortedKeys"]];
}
@end