mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-16 07:31:28 +00:00
Implement support for UNIX epoch initialization.
Add support for the +[CPDate dateWithTimeIntervalSince1970:] and -[CPDate initWithTimeIntervalSince1970].
This commit is contained in:
committed by
Ross Boucher
parent
ec3dcaa287
commit
1da9e93241
+9
-1
@@ -43,6 +43,9 @@ var CPDateReferenceDate = new Date(Date.UTC(2001,1,1,0,0,0,0));
|
||||
{
|
||||
return [[CPDate alloc] initWithTimeIntervalSinceNow:seconds];
|
||||
}
|
||||
+ (id)dateWithTimeIntervalSince1970:(CPTimeInterval)seconds {
|
||||
return [[CPDate alloc] initWithTimeIntervalSince1970:seconds];
|
||||
}
|
||||
+ (id)dateWithTimeIntervalSinceReferenceDate:(CPTimeInterval)seconds
|
||||
{
|
||||
return [[CPDate alloc] initWithTimeIntervalSinceReferenceDate:seconds];
|
||||
@@ -63,6 +66,11 @@ var CPDateReferenceDate = new Date(Date.UTC(2001,1,1,0,0,0,0));
|
||||
self = new Date((new Date()).getTime() + seconds * 1000);
|
||||
return self;
|
||||
}
|
||||
- (id)initWithTimeIntervalSince1970:(CPTimeInterval)seconds
|
||||
{
|
||||
self = new Date(seconds * 1000);
|
||||
return self;
|
||||
}
|
||||
- (id)initWithTimeIntervalSinceReferenceDate:(CPTimeInterval)seconds
|
||||
{
|
||||
self = [self initWithTimeInterval:seconds sinceDate:CPDateReferenceDate];
|
||||
@@ -129,4 +137,4 @@ var CPDateReferenceDate = new Date(Date.UTC(2001,1,1,0,0,0,0));
|
||||
|
||||
@end
|
||||
|
||||
Date.prototype.isa = CPDate;
|
||||
Date.prototype.isa = CPDate;
|
||||
|
||||
@@ -2,6 +2,14 @@ import <Foundation/CPDate.j>
|
||||
|
||||
@implementation CPDateTest : OJTestCase
|
||||
|
||||
- (void)testSince1970
|
||||
{
|
||||
/* These two dates should be equal to Fri Feb 13 2009 15:31:30 GMT-0800 */
|
||||
unixDate = [CPDate dateWithTimeIntervalSince1970: 1234567890];
|
||||
cocoaDate = [CPDate dateWithTimeIntervalSinceReferenceDate: 253582290];
|
||||
[self assertTrue:[unixDate isEqualToDate: cocoaDate]];
|
||||
}
|
||||
|
||||
- (void)testDate
|
||||
{
|
||||
var before = new Date();
|
||||
@@ -17,4 +25,4 @@ import <Foundation/CPDate.j>
|
||||
[self assert:middle equals:[middle laterDate:past] message:"laterDate incorrect"];
|
||||
}
|
||||
|
||||
@end
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user