UA-17470720-3

Jump to content


Photo
- - - - -

Performing Calendar Calculations on Parse:Date Data Definition Field-STV 4.05

data-definitions sections cells view-controllers

  • Please log in to reply
2 replies to this topic

#1 jet21

jet21

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 18 posts
Reputation: 0
Neutral

Posted 21 December 2014 - 07:11 PM

Hello Guys/Girls,

 

I have a Parse data definition Date input field on my app. I've also added a label (number of days) to the primary cell of the SCArrayOfObjects cell - STV 4.05. I've assigned a tag of 60 to the label. After the user selects/inputs a date on the app, I want to perform a calendar calculation on the user's inputed date to determine how many days there are between the user's selected date and the current date. 

 

After the calculation has been performed, I want to display the results/number of days between user's selected date and the current date on the label I've created with a tag of 60.

 

However, I'm having issues trying to produce the proper code to start the process of performing calendar calculations on the Parse "Date" definition field. The code I've started with below has issues - doesn't appear to work with STV 4.05:

 

 

SCPropertyDefinition *date = [accountInfo propertyDefinitionWithName:@"date"];

    dueDate.cellActions.willDisplay = ^(SCTableViewCell *cell, NSIndexPath *indexPath)

    

    {

        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

        [formatter setDateFormat:@"dd-MM-yyyy"];

        NSDate *startDate = [NSDate date];

        

        NSDate *endDate = [formatter dateFromString:@"dueDate"];

        

        NSCalendar *gregorian = [[NSCalendar alloc]

                                 initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

        

        NSUInteger unitFlags = NSCalendarUnitDay;

        

        NSDateComponents *components = [gregorian components:unitFlags

                                                    fromDate:startDate

                                                      toDate:endDate options:0];

        NSInteger day = [components day];

        

        NSLog(@"Days between %@ and %@ is: %ld", startDate, endDate, (long)[components day]);

 

 

    };

    

    

}

 

Please let me know if you have any suggestions.

 

Thanks....



#2 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 21 December 2014 - 08:23 PM

The code I've started with below has issues

 

 

yes it does 

 

NSDate *endDate = [formatter dateFromString:@"dueDate"];

 

dateFromString wants a date in a string like 01-01-2014.. dueDate is not a valid date string

 

if you want the value within the property of dueDate try something like [cell.boundObject valueForKey:@"date"] or something like that

NSDate *endDate = [formatter dateFromString:[NSString stringWithFormat:@"%@",[cell.boundObject valueForKey:@"date"]]];

  • Tarek likes this

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#3 jet21

jet21

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 18 posts
Reputation: 0
Neutral

Posted 22 December 2014 - 12:25 PM

yes it does 

 

NSDate *endDate = [formatter dateFromString:@"dueDate"];

 

dateFromString wants a date in a string like 01-01-2014.. dueDate is not a valid date string

 

if you want the value within the property of dueDate try something like [cell.boundObject valueForKey:@"date"] or something like that

NSDate *endDate = [formatter dateFromString:[NSString stringWithFormat:@"%@",[cell.boundObject valueForKey:@"date"]]];

Thanks for the quick reply Ozi! I'll try what you mentioned above...







Also tagged with one or more of these keywords: data-definitions, sections, cells, view-controllers

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users