commit missed file

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4763 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-08-25 16:15:12 +00:00
parent 6812c6aa5f
commit 388c61dbaa

View file

@ -18,7 +18,7 @@
You should have received a copy of the GNU Library General Public You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/ */
#include <config.h> #include <config.h>
@ -74,46 +74,46 @@
// //
// Getting an NSCalendar Date // Getting an NSCalendar Date
// //
+ (id)calendarDate + (id) calendarDate
{ {
id d = [[self alloc] init]; id d = [[self alloc] init];
return AUTORELEASE(d); return AUTORELEASE(d);
} }
+ (id)dateWithString: (NSString *)description + (id) dateWithString: (NSString *)description
calendarFormat: (NSString *)format calendarFormat: (NSString *)format
{ {
NSCalendarDate *d = [[NSCalendarDate alloc] initWithString: description NSCalendarDate *d = [[NSCalendarDate alloc] initWithString: description
calendarFormat: format]; calendarFormat: format];
return AUTORELEASE(d); return AUTORELEASE(d);
} }
+ (id)dateWithString: (NSString *)description + (id) dateWithString: (NSString *)description
calendarFormat: (NSString *)format calendarFormat: (NSString *)format
locale: (NSDictionary *)dictionary locale: (NSDictionary *)dictionary
{ {
NSCalendarDate *d = [[NSCalendarDate alloc] initWithString: description NSCalendarDate *d = [[NSCalendarDate alloc] initWithString: description
calendarFormat: format calendarFormat: format
locale: dictionary]; locale: dictionary];
return AUTORELEASE(d); return AUTORELEASE(d);
} }
+ (id)dateWithYear: (int)year + (id) dateWithYear: (int)year
month: (unsigned int)month month: (unsigned int)month
day: (unsigned int)day day: (unsigned int)day
hour: (unsigned int)hour hour: (unsigned int)hour
minute: (unsigned int)minute minute: (unsigned int)minute
second: (unsigned int)second second: (unsigned int)second
timeZone: (NSTimeZone *)aTimeZone timeZone: (NSTimeZone *)aTimeZone
{ {
NSCalendarDate *d = [[NSCalendarDate alloc] initWithYear: year NSCalendarDate *d = [[NSCalendarDate alloc] initWithYear: year
month: month month: month
day: day day: day
hour: hour hour: hour
minute: minute minute: minute
second: second second: second
timeZone: aTimeZone]; timeZone: aTimeZone];
return AUTORELEASE(d); return AUTORELEASE(d);
} }
@ -122,7 +122,7 @@
return [self class]; return [self class];
} }
- replacementObjectForPortCoder: aRmc - (id) replacementObjectForPortCoder: (NSPortCoder*)aRmc
{ {
return self; return self;
} }
@ -145,35 +145,38 @@
- (void) dealloc - (void) dealloc
{ {
RELEASE(calendar_format); RELEASE(calendar_format);
RELEASE(time_zone);
[super dealloc]; [super dealloc];
} }
// Initializing an NSCalendar Date /*
- (id)initWithString: (NSString *)description * Initializing an NSCalendar Date
*/
- (id) initWithString: (NSString *)description
{ {
// +++ What is the locale? // +++ What is the locale?
return [self initWithString: description return [self initWithString: description
calendarFormat: @"%Y-%m-%d %H:%M:%S %z" calendarFormat: @"%Y-%m-%d %H:%M:%S %z"
locale: nil]; locale: nil];
} }
- (id)initWithString: (NSString *)description - (id) initWithString: (NSString *)description
calendarFormat: (NSString *)format calendarFormat: (NSString *)format
{ {
// ++ What is the locale? // ++ What is the locale?
return [self initWithString: description return [self initWithString: description
calendarFormat: format calendarFormat: format
locale: nil]; locale: nil];
} }
// /*
// This function could possibly be written better * This function could possibly be written better
// but it works ok; currently ignores locale * but it works ok; currently ignores locale
// information and some specifiers. * information and some specifiers.
// */
- (id)initWithString: (NSString *)description - (id) initWithString: (NSString *)description
calendarFormat: (NSString *)format calendarFormat: (NSString *)format
locale: (NSDictionary *)locale locale: (NSDictionary *)locale
{ {
const char *d = [description cString]; const char *d = [description cString];
const char *f = [format cString]; const char *f = [format cString];
@ -195,7 +198,7 @@
// If either the string or format is nil then raise exception // If either the string or format is nil then raise exception
if (!description) if (!description)
[NSException raise: NSInvalidArgumentException [NSException raise: NSInvalidArgumentException
format: @"NSCalendar date description is nil"]; format: @"NSCalendar date description is nil"];
if (locale == nil) if (locale == nil)
locale = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]; locale = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
@ -465,13 +468,13 @@
timeZone: tz]; timeZone: tz];
} }
- (id)initWithYear: (int)year - (id) initWithYear: (int)year
month: (unsigned int)month month: (unsigned int)month
day: (unsigned int)day day: (unsigned int)day
hour: (unsigned int)hour hour: (unsigned int)hour
minute: (unsigned int)minute minute: (unsigned int)minute
second: (unsigned int)second second: (unsigned int)second
timeZone: (NSTimeZone *)aTimeZone timeZone: (NSTimeZone *)aTimeZone
{ {
int a; int a;
int c; int c;
@ -487,9 +490,9 @@
s += second; s += second;
// Assign time zone detail // Assign time zone detail
time_zone = [aTimeZone time_zone = RETAIN([aTimeZone
timeZoneDetailForDate: timeZoneDetailForDate:
[NSDate dateWithTimeIntervalSinceReferenceDate: s]]; [NSDate dateWithTimeIntervalSinceReferenceDate: s]]);
// Adjust date so it is correct for time zone. // Adjust date so it is correct for time zone.
s -= [time_zone timeZoneSecondsFromGMT]; s -= [time_zone timeZoneSecondsFromGMT];
@ -519,7 +522,7 @@
NSTimeInterval newOffset; NSTimeInterval newOffset;
oldOffset = [time_zone timeZoneSecondsFromGMT]; oldOffset = [time_zone timeZoneSecondsFromGMT];
time_zone = z; ASSIGN(time_zone, z);
newOffset = [time_zone timeZoneSecondsFromGMT]; newOffset = [time_zone timeZoneSecondsFromGMT];
s += newOffset - oldOffset; s += newOffset - oldOffset;
} }
@ -557,19 +560,24 @@
} }
// Default initializer // Default initializer
- (id)initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds - (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds
{ {
seconds_since_ref = seconds; seconds_since_ref = seconds;
if (!calendar_format) if (!calendar_format)
calendar_format = @"%Y-%m-%d %H:%M:%S %z"; calendar_format = @"%Y-%m-%d %H:%M:%S %z";
if (!time_zone) if (!time_zone)
time_zone = [[NSTimeZone localTimeZone] timeZoneDetailForDate: self]; time_zone = RETAIN([[NSTimeZone localTimeZone]
timeZoneDetailForDate: self]);
return self; return self;
} }
// Retreiving Date Elements // Retreiving Date Elements
- (void)getYear: (int *)year month: (int *)month day: (int *)day - (void) getYear: (int *)year
hour: (int *)hour minute: (int *)minute second: (int *)second month: (int *)month
day: (int *)day
hour: (int *)hour
minute: (int *)minute
second: (int *)second
{ {
int h, m; int h, m;
double a, b, c, d = [self dayOfCommonEra]; double a, b, c, d = [self dayOfCommonEra];
@ -594,7 +602,7 @@
*second = (int)c; *second = (int)c;
} }
- (int)dayOfCommonEra - (int) dayOfCommonEra
{ {
double a; double a;
int r; int r;
@ -608,7 +616,7 @@
return r; return r;
} }
- (int)dayOfMonth - (int) dayOfMonth
{ {
int m, d, y; int m, d, y;
@ -618,7 +626,7 @@
return d; return d;
} }
- (int)dayOfWeek - (int) dayOfWeek
{ {
int d = [self dayOfCommonEra]; int d = [self dayOfCommonEra];
@ -632,7 +640,7 @@
return d; return d;
} }
- (int)dayOfYear - (int) dayOfYear
{ {
int m, d, y, days, i; int m, d, y, days, i;
@ -645,7 +653,7 @@
return days; return days;
} }
- (int)hourOfDay - (int) hourOfDay
{ {
int h; int h;
double a, d = [self dayOfCommonEra]; double a, d = [self dayOfCommonEra];
@ -663,7 +671,7 @@
return h; return h;
} }
- (int)minuteOfHour - (int) minuteOfHour
{ {
int h, m; int h, m;
double a, b, d = [self dayOfCommonEra]; double a, b, d = [self dayOfCommonEra];
@ -680,7 +688,7 @@
return m; return m;
} }
- (int)monthOfYear - (int) monthOfYear
{ {
int m, d, y; int m, d, y;
@ -690,7 +698,7 @@
return m; return m;
} }
- (int)secondOfMinute - (int) secondOfMinute
{ {
int h, m, s; int h, m, s;
double a, b, c, d = [self dayOfCommonEra]; double a, b, c, d = [self dayOfCommonEra];
@ -710,7 +718,7 @@
return s; return s;
} }
- (int)yearOfCommonEra - (int) yearOfCommonEra
{ {
int m, d, y; int m, d, y;
int a; int a;
@ -725,7 +733,7 @@
} }
// Providing Adjusted Dates // Providing Adjusted Dates
- (NSCalendarDate *)addYear: (int)year - (NSCalendarDate*) addYear: (int)year
month: (unsigned int)month month: (unsigned int)month
day: (unsigned int)day day: (unsigned int)day
hour: (unsigned int)hour hour: (unsigned int)hour
@ -741,16 +749,14 @@
} }
// Getting String Descriptions of Dates // Getting String Descriptions of Dates
- (NSString *)description - (NSString*) description
{ {
return [self descriptionWithCalendarFormat: calendar_format return [self descriptionWithCalendarFormat: calendar_format locale: nil];
locale: nil];
} }
- (NSString *)descriptionWithCalendarFormat: (NSString *)format - (NSString*) descriptionWithCalendarFormat: (NSString *)format
{ {
return [self descriptionWithCalendarFormat: format return [self descriptionWithCalendarFormat: format locale: nil];
locale: nil];
} }
#define UNIX_REFERENCE_INTERVAL -978307200.0 #define UNIX_REFERENCE_INTERVAL -978307200.0
@ -1035,36 +1041,38 @@
if (newDate) if (newDate)
{ {
newDate->calendar_format = [calendar_format copyWithZone: zone]; newDate->calendar_format = [calendar_format copyWithZone: zone];
newDate->time_zone = RETAIN(time_zone);
} }
} }
return newDate; return newDate;
} }
- (NSString *)descriptionWithLocale: (NSDictionary *)locale - (NSString*) descriptionWithLocale: (NSDictionary *)locale
{ {
return [self descriptionWithCalendarFormat: calendar_format return [self descriptionWithCalendarFormat: calendar_format locale: locale];
locale: locale];
} }
// Getting and Setting Calendar Formats // Getting and Setting Calendar Formats
- (NSString *)calendarFormat - (NSString*) calendarFormat
{ {
return calendar_format; return calendar_format;
} }
- (void)setCalendarFormat: (NSString *)format - (void) setCalendarFormat: (NSString *)format
{ {
RELEASE(calendar_format); RELEASE(calendar_format);
calendar_format = [format copyWithZone: [self zone]]; calendar_format = [format copyWithZone: [self zone]];
} }
// Getting and Setting Time Zones // Getting and Setting Time Zones
- (void)setTimeZone: (NSTimeZone *)aTimeZone - (void) setTimeZone: (NSTimeZone *)aTimeZone
{ {
time_zone = [aTimeZone timeZoneDetailForDate: self]; NSTimeZoneDetail *detail = [aTimeZone timeZoneDetailForDate: self];
ASSIGN(time_zone, detail);
} }
- (NSTimeZoneDetail *)timeZoneDetail - (NSTimeZoneDetail*) timeZoneDetail
{ {
return time_zone; return time_zone;
} }
@ -1082,24 +1090,24 @@
@implementation NSCalendarDate (GregorianDate) @implementation NSCalendarDate (GregorianDate)
- (int)lastDayOfGregorianMonth: (int)month year: (int)year - (int) lastDayOfGregorianMonth: (int)month year: (int)year
{ {
switch (month) { switch (month) {
case 2: case 2:
if ((((year % 4) == 0) && ((year % 100) != 0)) if ((((year % 4) == 0) && ((year % 100) != 0))
|| ((year % 400) == 0)) || ((year % 400) == 0))
return 29; return 29;
else else
return 28; return 28;
case 4: case 4:
case 6: case 6:
case 9: case 9:
case 11: return 30; case 11: return 30;
default: return 31; default: return 31;
} }
} }
- (int)absoluteGregorianDay: (int)day month: (int)month year: (int)year - (int) absoluteGregorianDay: (int)day month: (int)month year: (int)year
{ {
int m, N; int m, N;
@ -1114,10 +1122,10 @@
+ (year - 1)/400); // ...plus prior years divisible by 400 + (year - 1)/400); // ...plus prior years divisible by 400
} }
- (void)gregorianDateFromAbsolute: (int)d - (void) gregorianDateFromAbsolute: (int)d
day: (int *)day day: (int *)day
month: (int *)month month: (int *)month
year: (int *)year year: (int *)year
{ {
// Search forward year by year from approximate year // Search forward year by year from approximate year
*year = d/366; *year = d/366;