discuss-gnustep
[Top][All Lists]
Advanced

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

Re: NSCalendar Issue


From: Stefan Bidi
Subject: Re: NSCalendar Issue
Date: Tue, 22 Jan 2013 08:23:42 -0600

It is entirely possible that NSCalendar is buggy.  I wrote this code 2
or 3 years ago and it has been relatively untested since then.

I just took a quick look at the code and it seems there is no test for
the year in -dateFromComponents:.  This explains why the year isn't
being picked up.  I won't have time to look into this until tonight,
but the fix seems trivial.

On Mon, Jan 21, 2013 at 11:59 PM, Abhi Beckert <abhi-l@abhibeckert.com> wrote:
> I'm having a problem with NSCalendar. This is the code I'm using:
>
>       NSCalendar *gregorian = [[NSCalendar alloc]
> initWithCalendarIdentifier:NSGregorianCalendar];
>
>       NSDate *midnightThisMorning = [NSDate date];
>       NSLog(@"%@", midnightThisMorning);
>
>       NSDateComponents *comps = [gregorian components:(NSYearCalendarUnit |
> NSMonthCalendarUnit |  NSDayCalendarUnit) fromDate:midnightThisMorning];
>       midnightThisMorning = [gregorian dateFromComponents:comps];
>       NSLog(@"%@", midnightThisMorning);
>
> It works on Mac OS X and iOS. I get:
>
>     2013-01-22 07:55:08 +1000
>     2013-01-22 00:00:00 +1000
>
> Bun on GNUstep I get this:
>
>     2013-01-22 07:55:08 +1000
>     1970-01-22 00:00:00 +1000
>
> For some reason the year (and possibly month?) doesn't get copied across to
> the new date.
>
> Am I doing something wrong? Or is NSCalendar buggy? All I really need is the
> UNIX timestamp for the beginning/end of the current day.
>
> - Abhi
>
>
>
> _______________________________________________
> Discuss-gnustep mailing list
> Discuss-gnustep@gnu.org
> https://lists.gnu.org/mailman/listinfo/discuss-gnustep
>



reply via email to

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