• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSDate: dates before the year 100
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDate: dates before the year 100


  • Subject: Re: NSDate: dates before the year 100
  • From: Jim Hamilton <email@hidden>
  • Date: Tue, 2 Aug 2005 12:15:01 -0400


On Aug 2, 2005, at 9:19 AM, Nick Zitzmann wrote:


On Aug 2, 2005, at 6:30 AM, Robert Kuilman wrote:


[NSDate dateWithNaturalLanguageString:@"Jan 25 33"];
[NSDate dateWithNaturalLanguageString:@"Jan 25 033"];
[NSDate dateWithNaturalLanguageString:@"Jan 25 0033"];

all return Jan 25 1933 as their value.

Any insights as to how to resolve this issue?


I'm not sure about BC dates, but this seems to work for the above:

[NSCalendarDate dateWithYear:33 month:1 day:25 hour:0 minute:0 second:0 timeZone:nil];

The first parameter can be negative. (At least, the documentation doesn't say otherwise, and a quick experiment shows that it works.) Then, you can do something like:


#import <Foundation/Foundation.h>

@interface NSCalendarDate (BCE_dates)

- (NSString *)yearAndEra;

@end

@implementation NSCalendarDate (BCE_dates)

- (NSString *)yearAndEra
{
    int year = [self yearOfCommonEra];
    if (year < 1)
    return [NSString stringWithFormat:@"%d B.C.E.", 1 - year];
    else
    return [NSString stringWithFormat:@"%d C.E.", year];
}

@end

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

// insert code here...
NSCalendarDate* cdate = [NSCalendarDate dateWithYear:-20 month: 1 day:25
hour:12 minute:0 second:0 timeZone:nil];
NSLog(@"%@", [cdate yearAndEra]);
[pool release];
return 0;
}

Output was:

[Session started at 2005-08-02 12:09:09 -0400.]
2005-08-02 12:09:09.862 dates[8448] year: 21 B.C.E.

dates has exited with status 0.

It wouldn't be too hard to add an init method that can take year and era...
--
Jim Hamilton


email@hidden
email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NSDate: dates before the year 100 (From: Robert Kuilman <email@hidden>)
 >Re: NSDate: dates before the year 100 (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Re: NSOutlineView and NSTreeController
  • Next by Date: Re: NSStatusBar generates Sigtrap
  • Previous by thread: Re: NSDate: dates before the year 100
  • Next by thread: Race Condition with NSPopUpButton.
  • Index(es):
    • Date
    • Thread