00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 @import "CPObject.j"
00024 @import "CPString.j"
00025
00026
00027 var CPDateReferenceDate = new Date(Date.UTC(2001,1,1,0,0,0,0));
00028
00029 @implementation CPDate : CPObject
00030 {
00031 }
00032
00033 + (id)alloc
00034 {
00035 return new Date;
00036 }
00037
00038 + (id)date
00039 {
00040 return [[self alloc] init];
00041 }
00042 + (id)dateWithTimeIntervalSinceNow:(CPTimeInterval)seconds
00043 {
00044 return [[CPDate alloc] initWithTimeIntervalSinceNow:seconds];
00045 }
00046 + (id)dateWithTimeIntervalSinceReferenceDate:(CPTimeInterval)seconds
00047 {
00048 return [[CPDate alloc] initWithTimeIntervalSinceReferenceDate:seconds];
00049 }
00050
00051 + (id)distantPast
00052 {
00053 return new Date(-10000,1,1,0,0,0,0);
00054 }
00055
00056 + (id)distantFuture
00057 {
00058 return new Date(10000,1,1,0,0,0,0);
00059 }
00060
00061 - (id)initWithTimeIntervalSinceNow:(CPTimeInterval)seconds
00062 {
00063 self = new Date((new Date()).getTime() + seconds * 1000);
00064 return self;
00065 }
00066 - (id)initWithTimeIntervalSinceReferenceDate:(CPTimeInterval)seconds
00067 {
00068 self = [self initWithTimeInterval:seconds sinceDate:CPDateReferenceDate];
00069 return self;
00070 }
00071 - (id)initWithTimeInterval:(CPTimeInterval)seconds sinceDate:(CPDate)refDate
00072 {
00073 self = new Date(refDate.getTime() + seconds * 1000);
00074 return self;
00075 }
00076 - (id)initWithString:(CPString)description
00077 {
00078 self = new Date(description);
00079 return self;
00080 }
00081
00082
00083 - (CPTimeInterval)timeIntervalSinceDate:(CPDate)anotherDate
00084 {
00085 return (self.getTime() - anotherDate.getTime()) / 1000.0;
00086 }
00087
00088 - (CPTimeInterval)timeIntervalSinceNow
00089 {
00090 return [self timeIntervalSinceDate:[CPDate date]];
00091 }
00092 - (CPTimeInterval)timeIntervalSince1970
00093 {
00094 return self.getTime() / 1000.0;
00095 }
00096 - (CPTimeInterval)timeIntervalSinceReferenceDate
00097 {
00098 return (self.getTime() - CPDateReferenceDate.getTime()) / 1000.0;
00099 }
00100 + (CPTimeInterval)timeIntervalSinceReferenceDate
00101 {
00102 return [[CPDate date] timeIntervalSinceReferenceDate];
00103 }
00104
00105 - (BOOL)isEqualToDate:(CPDate)anotherDate
00106 {
00107 return !(self < anotherDate || self > anotherDate);
00108 }
00109
00110 - (CPComparisonResult)compare:(CPDate)anotherDate
00111 {
00112 return (self > anotherDate) ? CPOrderedDescending : ((self < anotherDate) ? CPOrderedAscending : CPOrderedSame);
00113 }
00114
00115 - (CPDate)earlierDate:(CPDate)anotherDate
00116 {
00117 return (self < anotherDate) ? self : anotherDate;
00118 }
00119
00120 - (CPDate)laterDate:(CPDate)anotherDate
00121 {
00122 return (self > anotherDate) ? self : anotherDate;
00123 }
00124
00125 - (CPString)description
00126 {
00127 return self.toString();
00128 }
00129
00130 @end
00131
00132 Date.prototype.isa = CPDate;