mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-01 06:37:41 +00:00
Add support for encoding dates, courtesy of luddep.
This commit is contained in:
@@ -185,4 +185,25 @@ var CPDateReferenceDate = new Date(Date.UTC(2001,1,1,0,0,0,0));
|
||||
|
||||
@end
|
||||
|
||||
var CPDateTimeKey = @"CPDateTimeKey";
|
||||
|
||||
@implementation CPDate (CPCoding)
|
||||
|
||||
- (id)initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
if (self)
|
||||
{
|
||||
self.setTime([aCoder decodeIntForKey:CPDateTimeKey]);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
[aCoder encodeInt:self.getTime() forKey:CPDateTimeKey];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Date.prototype.isa = CPDate;
|
||||
|
||||
@@ -43,6 +43,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testEncoding
|
||||
{
|
||||
var date = new Date(),
|
||||
encodedDate = [CPKeyedArchiver archivedDataWithRootObject:date],
|
||||
decodedDate = [CPKeyedUnarchiver unarchiveObjectWithData:encodedDate];
|
||||
|
||||
[self assert:date equals:decodedDate];
|
||||
}
|
||||
|
||||
- (void)testDescription
|
||||
{
|
||||
// Unfortunately the result will be different depending on the testing machine's timezone.
|
||||
|
||||
Reference in New Issue
Block a user