Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5969463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:14:04+00:00 2026-05-22T20:14:04+00:00

So I seem to be getting burned by the iPhone’s calendar support again .

  • 0

So I seem to be getting burned by the iPhone’s calendar support again. I’ve come across an issue with the way core data compares dates. Core data appears to be storing dates using the Gregorian calendar as they come out in a 20XX-MM-dd format. But when I build an NSPredicate this way

[nsRequest setPredicate:[NSPredicate predicateWithFormat:@"publish <= %@ AND expires >= %@", [NSDate date], [NSDate date]]]

if the user’s device isn’t set to a Gregorian calendar then no items will appear, as core data doesn’t seem to localizing it’s NSDates before comparing against the input dates.

So it would appear that if the date were today ‘2011-05-31’ in Japanese calendar mode core data is using ‘0023-05-31’ since it’s the 23rd year of the current emperor, placing the input date about 2000 years before what it’s being compared against.

I’ve found I can work around this like so

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:[[NSLocale preferredLanguages] objectAtIndex:0]] autorelease]];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZ"];
NSString *todayGregorian = [[dateFormat stringFromDate:[NSDate date]] retain];
[dateFormat release];

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZ"];
[nsRequest setPredicate:[NSPredicate predicateWithFormat:@"publish <= %@ AND expires >= %@", [df dateFromString:todayGregorian], [df dateFromString:todayGregorian]]];

but I’m hoping that maybe I’m being an idiot and there’s a better way. Any suggestions?

Please note:

  • Asking my Japanese users to change
    the date format they use isn’t an
    option.
  • Also, I still need to store
    the core data dates in a Gregorian
    format, as these users do sometimes
    change their calendars back and
    forth.

Real problem
My solution above is wrong. TechZen’s answer kicked my head in to gear and I wish I could up vote him 100 times, I ended up solving the issue.

My problem is data going in to Core Data is being sent by the server in GMT and the formmater parsing that data might not necessarily be in GMT so I need to adjust the time going in to Core Data correctly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:14:05+00:00Added an answer on May 22, 2026 at 8:14 pm

    You really have no choice but to translate from NSDate to various calendars, especially if your users employ multiple calendars.

    Calendar objects are not dates themselves but rather specialized formatters. All dates are actually stored in the GMT standard format regardless of the calendar they originated with. Then they are translated/formatted to the appropriate calendar as needed. We don’t see this immediately in apps targeted towards Westerners because contemporary Western calendars are based on the GMT so no translation appears needed.

    Date and time programming is deceptively complex. We don’t intuitive feel it is complex because so much of the grunt work is usually handled for us. However, when you start doing something unusual, the complexity because readily apparent.

    As a rule of thumb, the time to worry with data and time programming is not when the code seems to complex but when it seems to simple.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to be getting a strange error when I run my tests in
I seem to be getting breakpoints from other programmers when checking out code... Where
I seem to be getting a type mismatch error when trying to do something
I am getting very frustrated because I cannot seem to figure out why Collections
I keep getting this NPE in my application and I can't seem to get
I'm getting confused with the include/exclude jargon, and my actual SVN client doesn't seem
In one of our application im getting an exception that i can not seem
I must be getting daft, but I can't seem to find how to read
I'm still getting used to the sizers in wxWidgets, and as such can't seem
Seem to be having an issue with std::auto_ptr and assignment, such that the object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.