New: CPDate dateByAddingTimeInterval:.

Refs #2126.
This commit is contained in:
Alexander Ljungberg
2014-06-03 17:41:35 +01:00
parent effd837cd0
commit 7c6ef51cb2
2 changed files with 33 additions and 0 deletions
+9
View File
@@ -146,6 +146,15 @@ var CPDateReferenceDate = new Date(Date.UTC(2001, 0, 1, 0, 0, 0, 0));
return [[CPDate date] timeIntervalSinceReferenceDate];
}
/**
Return a new date representing the receiver's time plus the given interval into the future,
or into the past for a negative interval.
*/
- (id)dateByAddingTimeInterval:(CPTimeInterval)seconds
{
return [[CPDate alloc] initWithTimeInterval:seconds sinceDate:self];
}
- (BOOL)isEqual:(CPDate)aDate
{
if (self === aDate)
+24
View File
@@ -35,6 +35,30 @@
[self assert:middle equals:[middle laterDate:past] message:"laterDate incorrect"];
}
- (void)testDateByAddingTimeIntervalZeroShouldReturnSameDate
{
var a = [CPDate dateWithTimeIntervalSince1970:1231889490.0],
b = [a dateByAddingTimeInterval:0];
[self assert:[b timeIntervalSince1970] equals:1231889490];
}
- (void)testDateByAddingTimeIntervalPositiveShouldReturnNewerDate
{
var a = [CPDate dateWithTimeIntervalSince1970:1231889490.0],
b = [a dateByAddingTimeInterval:789];
[self assert:[b timeIntervalSince1970] equals:1231889490 + 789];
}
- (void)testDateByAddingTimeIntervalNegativeShouldReturnOlderDate
{
var a = [CPDate dateWithTimeIntervalSince1970:1231889490.0],
b = [a dateByAddingTimeInterval:-789];
[self assert:[b timeIntervalSince1970] equals:1231889490 - 789];
}
- (void)testEquals
{
var now = [CPDate date];