[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSCalendarDate problem

From: Richard Frith-Macdonald
Subject: Re: NSCalendarDate problem
Date: Thu, 3 Jul 2003 21:32:06 +0100

On Thursday, July 3, 2003, at 08:24  pm, Andreas Hoeschler wrote:

Hello Richard,

GNUstep is obviously trying to be tolerant of programmer errors, and restrict the arguments to the valid range. What behavior are you expecting? Do you know if MacOS-X causes an exception to be raised or the object to be deallocated and nil returned? The OpenStep spec and MacOS-X documentation don't specify the behavior, so technically there's nothing wrong with the current behavior.

Imagine you have an interface with a field where users are supposed to enter times. I have specified the format %H:%M. NSCalendarDate is to be used to hold the time.

NSCalendarDate *date = [NSCalendarDate dateWithString:@"18:00" calendarFormat:@"%H:%M"];
      NSLog(@"date %@", date);

2003-07-03 21:17:17.340 FBTest[20695] date 0000-01-02 06:00:00 +0100

NSCalendarDate *date = [NSCalendarDate dateWithString:@"23:59" calendarFormat:@"%H:%M"];
      NSLog(@"date %@", date);

2003-07-03 21:21:19.064 FBTest[20772] date 0000-01-02 00:01:00 +0100

Is this correct behaviour? I don't think so. If it is please enlighten me. I am using a database adaptor that reads a time from the database and uses

No ... that's not correct behavior ... the calendar format was not being set correctly, so the output was in the wrong format (not HH:MM). It's fixed in CVS now.

NSCalendarDate *date = [[NSCalendarDate alloc] initWithYear:0 month:0 day:0 hour:18 minute:0 second:0 timeZone:nil];

to create an NSCalendarDate from just two integers. This works as expected on MacOSX. However, it produces

2003-07-03 20:44:40.516 FBTest[18838] File NSCalendarDate.m: 1239. In [NSCalendarDate -initWithYear:month:day:hour:minute:second:timeZone:] invalid month given - 0

on GNUstep. I think there is something wrong with the current behaviour.

In this case, your code is just wrong, as the documentation explicitly says you use a value of 1 to 12 for the month and 1 to 31 for day. I don't know what you 'expect' and how MacOS-X works 'as expected' ... if you read the documentation for other intialisers too, I think you would most likely expect the variable 'date' to be set to nil.

You should be setting a valid year, month, day and second.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]