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

  • Home
  • SEARCH
  • 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 8056029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:35:07+00:00 2026-06-05T08:35:07+00:00

Following code shows the problem: Advancing a full year from the first day of

  • 0

Following code shows the problem: Advancing a full year from the first day of the year 1435 does not result in the first day of 1436.

Any ideas what i’m missing?

NSDateComponents *components = [[NSDateComponents alloc] init];
[components setDay:1];
[components setMonth:1];
[components setYear:1435];


NSCalendar *islamic = [[NSCalendar alloc] initWithCalendarIdentifier:NSIslamicCalendar];
NSDate *date = [islamic dateFromComponents:components];

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setCalendar:islamic];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];

NSLog(@"%@", [dateFormatter stringFromDate:date]);  // -> 01.01.1435

NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
[offsetComponents setYear:1];

NSDate *dateWithOffset = [islamic dateByAddingComponents:offsetComponents toDate:date options:0];

NSLog(@"%@", [dateFormatter stringFromDate:dateWithOffset]); 
// -> 30.12.1435 ... WHY NOT 01.01.1436 ????
  • 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-06-05T08:35:09+00:00Added an answer on June 5, 2026 at 8:35 am

    My suspicion is because of summertime/wintertime (daylight savings time) difference. Muh. 1, 1435 falls on November 5, 2013, while Muh. 1, 1436 falls on October 25, 2014. The first date is during wintertime, the second during summertime.

    The first NSDate you created is exactly November 5, 2013 00:00 (at midnight). “dateByAddingComponents:” works by converting the components to seconds, and adding that to the first date. In this case, the result is October 24, 2014 23:00, because of the summertime.

    This would also mean that the results could be different for different people around the world because of daylight saving time differences between timezones.

    You can prevent the problem by setting the first date to mid-day, instead of midnight (which is in general a good idea when working with pure dates):

    NSDateComponents *components = [[NSDateComponents alloc] init];
    [components setDay:1];
    [components setMonth:1];
    [components setYear:1435];
    [components setHour:12];
    

    Now, whether this is correct behaviour of “dateByAddingComponents” is another question.

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

Sidebar

Related Questions

The following code shows my problem. plotyy completely fails if the ticks are not
In the following code, the first log statement shows a decimal as expected, but
Spoiler alert: this is related to Problem 14 from Project Euler. The following code
another beginner problem. Why isn't the following code with an asp.net page not working?
I have quite an embarrassing problem. The following code simply will not create a
I have a problem with the following example code that shows inconsistent behavior for
The following code shows the problem I am experiencing: // Assume working directory is
The following code shows a segmentation error. How to solve the problem? What is
The following code shows error as StandardOut has not been redirected or the process
The following code shows a button that allows you to select a file (should

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.