@@ -225,11 +225,11 @@ sec += sec_; usec += usec_; while (usec > 999999) { - usec -= 999999; + usec -= 10000000; sec++; } return self; } @@ -361,11 +361,11 @@ @try { # endif struct tm *tmp; - if ((tmp = gmtime(&sec)) == NULL) + if ((tmp = gmtime(&sec_)) == NULL) @throw [OFOutOfRangeException newWithClass: isa]; tm = *tmp; # ifdef OF_THREADS } @finally { @@ -404,11 +404,11 @@ @try { # endif struct tm *tmp; - if ((tmp = localtime(&sec)) == NULL) + if ((tmp = localtime(&sec_)) == NULL) @throw [OFOutOfRangeException newWithClass: isa]; tm = *tmp; # ifdef OF_THREADS } @finally { @@ -442,10 +442,51 @@ if ([self compare: date] == OF_ORDERED_ASCENDING) return [[date retain] autorelease]; return [[self retain] autorelease]; } + +- (int64_t)timeIntervalSince1970 +{ + return sec; +} + +- (uint32_t)microsecondsOfTimeIntervalSince1970 +{ + return usec; +} + +- (int64_t)timeIntervalSinceDate: (OFDate*)date +{ + int64_t sec_ = sec - date->sec; + int32_t usec_ = (int32_t)usec - date->usec; + + while (usec_ > 999999) { + usec_ -= 1000000; + sec_++; + } + + while (usec < 0) { + usec_ += 1000000; + sec_--; + } + + return sec_; +} + +- (uint32_t)microsecondsOfTimeIntervalSinceDate: (OFDate*)date +{ + int32_t usec_ = (int32_t)usec - date->usec; + + while (usec_ > 999999) + usec_ -= 1000000; + + while (usec < 0) + usec_ += 1000000; + + return usec_; +} - (OFDate*)dateByAddingTimeInterval: (int64_t)sec_ { return [self dateByAddingTimeInterval: sec_ withMicroseconds: 0]; @@ -456,13 +497,13 @@ { sec_ += sec; usec_ += usec; while (usec_ > 999999) { - usec_ -= 999999; + usec_ -= 1000000; sec_++; } return [OFDate dateWithTimeIntervalSince1970: sec_ microseconds: usec_]; } @end