37 var result =
new Date;
38 result.isa = [
self class];
44 return [[
self alloc] init];
47 + (id)dateWithTimeIntervalSinceNow:(CPTimeInterval)seconds
52 + (id)dateWithTimeIntervalSince1970:(CPTimeInterval)seconds
57 + (id)dateWithTimeIntervalSinceReferenceDate:(CPTimeInterval)seconds
72 - (id)initWithTimeIntervalSinceNow:(CPTimeInterval)seconds
74 if (!_isNumberType(seconds))
75 CPLog.warn(
@"The parameter of the method initWithTimeIntervalSinceNow: should be an integer or a float");
77 self =
new Date((
new Date()).getTime() + seconds * 1000);
81 - (id)initWithTimeIntervalSince1970:(CPTimeInterval)seconds
83 if (!_isNumberType(seconds))
84 CPLog.warn(
@"The parameter of the method initWithTimeIntervalSince1970: should be an integer or a float");
86 self =
new Date(seconds * 1000);
90 - (id)initWithTimeIntervalSinceReferenceDate:(CPTimeInterval)seconds
92 if (!_isNumberType(seconds))
93 CPLog.warn(
@"The parameter of the method initWithTimeIntervalSinceReferenceDate: should be an integer or a float");
99 - (id)initWithTimeInterval:(CPTimeInterval)seconds sinceDate:(
CPDate)refDate
101 if (!_isNumberType(seconds))
102 CPLog.warn(
@"The parameter of the method initWithTimeInterval:sinceDate: should be an integer or a float");
104 self =
new Date(refDate.getTime() + seconds * 1000);
115 var format =
new RegExp(
"(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2}) ([-+])(\\d{2})(\\d{2})"),
118 if (!d || d.length != 10)
120 reason:"initWithString: the string must be in YYYY-MM-DD HH:MM:SS 1HHMM format"];
122 var date =
new Date(d[1], d[2] - 1, d[3]),
123 timeZoneOffset = (Number(d[8]) * 60 + Number(d[9])) * (d[7] ===
'-' ? 1 : -1);
126 date.setMinutes(d[5]);
127 date.setSeconds(d[6]);
129 self =
new Date(date.getTime() + (timeZoneOffset - date.getTimezoneOffset()) * 60 * 1000);
133 - (CPTimeInterval)timeIntervalSinceDate:(
CPDate)anotherDate
135 return (
self.getTime() - anotherDate.getTime()) / 1000.0;
138 - (CPTimeInterval)timeIntervalSinceNow
143 - (CPTimeInterval)timeIntervalSince1970
145 return self.getTime() / 1000.0;
148 - (CPTimeInterval)timeIntervalSinceReferenceDate
153 + (CPTimeInterval)timeIntervalSinceReferenceDate
162 - (id)dateByAddingTimeInterval:(CPTimeInterval)seconds
172 if (!aDate || ![aDate isKindOfClass:[
CPDate class]])
183 return !(self < aDate || self > aDate);
186 - (CPComparisonResult)compare:(
CPDate)anotherDate
193 return (
self < anotherDate) ? self : anotherDate;
198 return (
self > anotherDate) ? self : anotherDate;
204 + (
CPString)timezoneOffsetString:(
int)timezoneOffset
206 var offset = -timezoneOffset,
207 positive = offset >= 0,
208 hours = positive ? FLOOR(offset / 60) : CEIL(offset / 60),
209 minutes = offset - hours * 60;
224 return new Date(
self.getTime());
245 [aCoder encodeInt:self.getTime() forKey:CPDateTimeKey];
253 Date.parseISO8601 =
function (date)
260 timestamp = Date.parse(date);
262 if (isNaN(timestamp) && (
struct =
new RegExp(
"^(\\d{4}|[+\\-]\\d{6})(?:-(\\d{2})(?:-(\\d{2}))?)?(?:T(\\d{2}):(\\d{2})(?::(\\d{2})(?:\\.(\\d{3}))?)?(?:(Z)|([+\\-])(\\d{2})(?::(\\d{2}))?)?)?$").exec(date)))
266 struct[k] = +
struct[k] || 0;
269 struct[2] = (+
struct[2] || 1) - 1;
270 struct[3] = +
struct[3] || 1;
272 if (
struct[8] !==
'Z' &&
struct[9] !== undefined)
274 minutesOffset =
struct[10] * 60 +
struct[11];
276 if (
struct[9] ===
'+')
277 minutesOffset = 0 - minutesOffset;
280 return Date.UTC(
struct[1],
struct[2],
struct[3],
struct[4],
struct[5] + minutesOffset,
struct[6],
struct[7]);
288 function _isNumberType(value)
290 if (typeof value ===
'number')
Used to implement exception handling (creating & raising).
CPString timezoneOffsetString:(int timezoneOffset)
A representation of a single point in time.
CPTimeInterval timeIntervalSinceDate:(CPDate anotherDate)
void raise:reason:(CPString aName, [reason] CPString aReason)
id dateWithTimeIntervalSinceReferenceDate:(CPTimeInterval seconds)
id initWithTimeIntervalSince1970:(CPTimeInterval seconds)
An immutable string (collection of characters).
BOOL isEqualToDate:(CPDate aDate)
id initWithTimeIntervalSinceReferenceDate:(CPTimeInterval seconds)
Defines methods for use when archiving & restoring (enc/decoding).
id initWithTimeIntervalSinceNow:(CPTimeInterval seconds)
id initWithTimeInterval:sinceDate:(CPTimeInterval seconds, [sinceDate] CPDate refDate)
CPTimeInterval timeIntervalSinceReferenceDate()
id stringWithFormat:(CPString format, [,] ...)
FrameUpdater prototype description