diff --git a/ChangeLog b/ChangeLog index 2237aa2e7..ac1d44989 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,8 @@ * Source/Additions/GSFunctions.m: New file for extra functions. * Source/NSString.m: ([stringByExpandingTildeInPath]) Improve handling of paths containing mingw drives. + * Source/NSDate.m: Use same values for distant past/future as MacOSX + * Source/NSCalendarDate.m: Support output of extreme year values. 2005-03-14 Adam Fedor diff --git a/Source/NSCalendarDate.m b/Source/NSCalendarDate.m index 94ee8c6b4..a7cc66ef5 100644 --- a/Source/NSCalendarDate.m +++ b/Source/NSCalendarDate.m @@ -1742,25 +1742,37 @@ static void Grow(DescriptionInfo *info, unsigned size) ycent = YES; case 'y': v = info->yd; - if (v < 0) - v = 0; - if (v > 9999) - v = 9999; if (ycent) { - Grow(info, 4); - info->t[info->offset+3] = (v%10) + '0'; - v /= 10; - info->t[info->offset+2] = (v%10) + '0'; - v /= 10; - info->t[info->offset+1] = (v%10) + '0'; - v /= 10; - info->t[info->offset+0] = (v%10) + '0'; - info->offset += 4; + if (v >= 0 && v <= 9999) + { + Grow(info, 4); + info->t[info->offset+3] = (v%10) + '0'; + v /= 10; + info->t[info->offset+2] = (v%10) + '0'; + v /= 10; + info->t[info->offset+1] = (v%10) + '0'; + v /= 10; + info->t[info->offset+0] = (v%10) + '0'; + info->offset += 4; + } + else + { + unsigned char tmp[16]; + int idx = 0; + + sprintf(tmp, "%d", v); + Grow(info, strlen(tmp)); + while (tmp[idx] != '\0') + { + info->t[info->offset++] = tmp[idx++]; + } + } } else { Grow(info, 2); + if (v < 0) v = -v; v = v % 100; info->t[info->offset+1] = (v%10) + '0'; v /= 10; diff --git a/Source/NSDate.m b/Source/NSDate.m index 1005a2133..0948e6eda 100644 --- a/Source/NSDate.m +++ b/Source/NSDate.m @@ -50,10 +50,9 @@ #include #include "GSPrivate.h" -/* I hope 100,000 years is distant enough. */ -#define DISTANT_YEARS 100000.0 -#define DISTANT_FUTURE (DISTANT_YEARS * 365.0 * 24 * 60 * 60) -#define DISTANT_PAST (-DISTANT_FUTURE) +/* These constants seem to be what MacOS-X uses */ +#define DISTANT_FUTURE 63113990400.0 +#define DISTANT_PAST -63113817600.0 const NSTimeInterval NSTimeIntervalSince1970 = 978307200.0; diff --git a/Testing/nsdate.m b/Testing/nsdate.m index 8e27e04e5..34aea29d6 100644 --- a/Testing/nsdate.m +++ b/Testing/nsdate.m @@ -27,6 +27,8 @@ main() pool = [[NSAutoreleasePool alloc] init]; + NSLog(@"%@", [NSCalendarDate distantFuture]); + NSLog(@"%@", [NSCalendarDate distantPast]); NSLog(@"%@", [NSCalendarDate dateWithNaturalLanguageString: @"01-08-2002 00:00:00"]); NSLog(@"%@", [NSCalendarDate dateWithNaturalLanguageString: @"31-08-2002 23:59:59"]);