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
00032 @implementation CPDate : CPObject
00033 {
00034 }
00035
00036 + (id)alloc
00037 {
00038 return new Date;
00039 }
00040
00041 + (id)date
00042 {
00043 return [[self alloc] init];
00044 }
00045
00046 + (id)dateWithTimeIntervalSinceNow:(CPTimeInterval)seconds
00047 {
00048 return [[CPDate alloc] initWithTimeIntervalSinceNow:seconds];
00049 }
00050
00051 + (id)dateWithTimeIntervalSince1970:(CPTimeInterval)seconds
00052 {
00053 return [[CPDate alloc] initWithTimeIntervalSince1970:seconds];
00054 }
00055
00056 + (id)dateWithTimeIntervalSinceReferenceDate:(CPTimeInterval)seconds
00057 {
00058 return [[CPDate alloc] initWithTimeIntervalSinceReferenceDate:seconds];
00059 }
00060
00061 + (id)distantPast
00062 {
00063 return new Date(-10000,1,1,0,0,0,0);
00064 }
00065
00066 + (id)distantFuture
00067 {
00068 return new Date(10000,1,1,0,0,0,0);
00069 }
00070
00071 - (id)initWithTimeIntervalSinceNow:(CPTimeInterval)seconds
00072 {
00073 self = new Date((new Date()).getTime() + seconds * 1000);
00074 return self;
00075 }
00076
00077 - (id)initWithTimeIntervalSince1970:(CPTimeInterval)seconds
00078 {
00079 self = new Date(seconds * 1000);
00080 return self;
00081 }
00082
00083 - (id)initWithTimeIntervalSinceReferenceDate:(CPTimeInterval)seconds
00084 {
00085 self = [self initWithTimeInterval:seconds sinceDate:CPDateReferenceDate];
00086 return self;
00087 }
00088
00089 - (id)initWithTimeInterval:(CPTimeInterval)seconds sinceDate:(CPDate)refDate
00090 {
00091 self = new Date(refDate.getTime() + seconds * 1000);
00092 return self;
00093 }
00094
00095 - (id)initWithString:(CPString)description
00096 {
00097 self = new Date(description);
00098 return self;
00099 }
00100
00101 - (CPTimeInterval)timeIntervalSinceDate:(CPDate)anotherDate
00102 {
00103 return (self.getTime() - anotherDate.getTime()) / 1000.0;
00104 }
00105
00106 - (CPTimeInterval)timeIntervalSinceNow
00107 {
00108 return [self timeIntervalSinceDate:[CPDate date]];
00109 }
00110
00111 - (CPTimeInterval)timeIntervalSince1970
00112 {
00113 return self.getTime() / 1000.0;
00114 }
00115
00116 - (CPTimeInterval)timeIntervalSinceReferenceDate
00117 {
00118 return (self.getTime() - CPDateReferenceDate.getTime()) / 1000.0;
00119 }
00120
00121 + (CPTimeInterval)timeIntervalSinceReferenceDate
00122 {
00123 return [[CPDate date] timeIntervalSinceReferenceDate];
00124 }
00125
00126 - (BOOL)isEqualToDate:(CPDate)anotherDate
00127 {
00128 return !(self < anotherDate || self > anotherDate);
00129 }
00130
00131 - (CPComparisonResult)compare:(CPDate)anotherDate
00132 {
00133 return (self > anotherDate) ? CPOrderedDescending : ((self < anotherDate) ? CPOrderedAscending : CPOrderedSame);
00134 }
00135
00136 - (CPDate)earlierDate:(CPDate)anotherDate
00137 {
00138 return (self < anotherDate) ? self : anotherDate;
00139 }
00140
00141 - (CPDate)laterDate:(CPDate)anotherDate
00142 {
00143 return (self > anotherDate) ? self : anotherDate;
00144 }
00145
00146 - (CPString)description
00147 {
00148 return self.toString();
00149 }
00150
00151 @end
00152
00153 Date.prototype.isa = CPDate;