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 1019859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:04:40+00:00 2026-05-16T11:04:40+00:00

i have got a function with BOOL return value and 2 input (NSDateComponents *)

  • 0

i have got a function with BOOL return value and 2 input (NSDateComponents *) parameters.
My trouble is I have two NSDateComponents values and I want to know if the two date fall within the same calendar week. i tried the simplest solutions to solve problem, my idea was the following:


- (BOOL)isFunctionName:(NSDateComponents *)comp1 andParam:(NSDateComponents *)comp2 {
return (([comp1 week] == [comp2 week]) && ([comp1 year] == [comp2 year]));
}

but it’s not correct.
what way i can solve it ?


edited

so i have a function which makes datecomponents from dates.


-(NSDateComponents *)dateToDateComponents:(NSDate *)date {
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponents = [gregorian components:unitFlags fromDate:date];
[gregorian release];
return dateComponents;
}

and i call it this way:


if ([self isFunctionName: [self dateToDateComponents:startDate] and Param:[self dateToDateComponents:currentTripDate]]){
}

and during my test it returns YES all of my dates (for example 2010.07.21 – 2010.08.18)

  • 1 1 Answer
  • 1 View
  • 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-16T11:04:41+00:00Added an answer on May 16, 2026 at 11:04 am

    The NSDateComponent class reference states:

    Important: An NSDateComponents object is meaningless in itself; you
    need to know what calendar it is
    interpreted against, and you need to
    know whether the values are absolute
    values of the units, or quantities of
    the units.

    What about comparing NSDates instead?

    - (BOOL) weekIsEqual:(NSDate *)date and:(NSDate *)otherDate {
      NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
    
      NSDateComponents *dateComponents      = [gregorian components:NSWeekdayCalendarUnit | NSYearCalendarUnit fromDate:date];
      NSDateComponents *otherDateComponents = [gregorian components:NSWeekdayCalendarUnit | NSYearCalendarUnit fromDate:otherDate];
    
      return [dateComponents week] == [otherDateComponents week] && [dateComponents year] == [otherDateComponents year];
    }
    

    edit:
    In this line:

     unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
    

    You don’t pass NSWeekCalendarUnit, therefore [dateComponent week] returns NSUndefinedDateComponent

    edit

    Of course, it has to be NSWeekCalendarUnit…

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

Sidebar

Related Questions

If I want the unordered map find function to return a bool value, how
I have got two pages. example.com/php.com and example.com. I use this function to set
I have got this code: function init(){ if (typeof window.jQuery !== 'function') { var
I have got a problem with calling a global function, which takes a pointer
I have got the following very simple code: function init() { var articleTabs =
I have got the following issue, my function appends code to a string $string
I have got code like this var challegneListener; $(document).ready(function(){ var challegneListener = setInterval(challengeListenerBot(),5000); });
I am imlementing a simple merge function and I have got stuck, as the
Code is not running on .click when I have this: $(.cancel).click(function() { alert(got here);
I've got a simple C class I have implemented, using function pointers in a

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.