Parse check if object was created today? Objective-C - objective-c

I am trying to write a PFQuery for my application that returns only objects that were created today. With all the depreciations that happened to NSDate and the growing importance of NSDateFormatter I am finding rather hard to go about this.
I have figured the logic to be like this in pseudo-code:
Query q = new Query();
q.whereDateGreaterThan(midnightThisMorning);
q.whereDateLessThan(midnightTonight);
I can't seem to figure out how to get a NSDate object set to 12:00 AM (which would be midnightThisMorning) and another set to 11:59 PM tonight (which would be midnightTonight).

Check out NSCalendar's startOfDayForDate method to find the start of the current day.
To find the end of the current day, you'll want to add a day to the date returned from startOfDayForDate and then subtract one second.

Related

convert json utc "/Date(1420095600000-0700)/" date to nsdate

I get date like "/Data(xxx....xxx-xxxx)" from api. How can i get nsdate form this format. Temporarily I solved this problem to truncate the string and get seconds. but I need proper solution for this problem. kindly help me
Use NSDateFormater to transform this String (the parts within the brackets) into an NSDate and vice versa. See the docs here: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/#//apple_ref/occ/instp/NSDateFormatter/dateFormat and here about the various formating possibilities: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/DataFormatting/DataFormatting.html#//apple_ref/doc/uid/10000029i
Well, you may have to get rid of the milliseconds.

How to get work days and absence days of an employee (resource)?

How do I get the work and absence days of an employee with VBA from MS-Project? (an employee is a ressource)
Some additional infos:
I know how to get tasks
Dim ts as Tasks
Set ts = ActiveProject.Tasks
and I know how to get ressources from my project file:
Dim rs as Resources
Set rs = ActiveProject.ressources
but I do not find a (trivial) way to get work and absence days from this variables.
You need to look at the Resource object to find the working and non-working days:
ActiveProject.Resources.Item(1).Calendar
In this trivial example we're picking up the first resource in the project and pulling out it's associated Calendar.
A resource calendar will have a base calendar from which it inherits:
...Calendar.BaseCalendar
and both the resource calendar and the base calendar define working days, working weeks and exceptions. Exceptions are typically how periods of absence are defined... i.e. they are exceptions to the normal pattern of work:
...Calendar.WorkWeeks
...Calendar.WeekDays
...Calendar.Exceptions
The answer already provided information to get one started, but does not actually answer the question. As stated, "Exceptions" are indeed how periods of absence are defined but to determine if a given date is an absence day from the exception object will take a not-insignificant amout of parsing code.
It would be a lot simpler and much more reliable to determine workdays empirically. Assuming variable "cal" is the calendar in question declare a variable (say "d") of type long then loop from some start date to some end date-1 and determine if that date is a workday or not using Application.datedifference (d, d+1, cal). A non work day will yield 0.

Returned Date as a string timestamp (Unix?) not sure

I'm working with some videogame server data. The server returns a dictionary with past game details. One of the fields is for the date. That returned object is a string like this:
/Date(1286749014000-0700)/
I'm not exactly sure how that string translates into the date, but it should represent Sunday, October 10, 2010, 3:16 PM.
Is this a Unix timestamp? Do they usually have a suffix like -0700?
Thank you
The number 1286749014 stands for 10 october 2010 5:16:54 pm. So if you substract the 700 from it you should get the right date and time.
Check out the Wikipedia article on Unix time for more information on how it's made up.
The first part ("128674901") exactly represents "Sun, 10 Oct 2010 22:16:54 GMT" date.
In objective-c you can use something like this:
NSTimeInterval unixDate = 128674901;
NSDate *date = [NSDate dateWithTimeIntervalSince1970:unixDate];
It looks like you have a high resolution time with timezone offset.
The "0700" suffix is a time zone.
Which means UTC -07

Is there an easy way with NSDateFormatter to get "Today", "Tomorrow","Friday" style dates?

I'm working on setting up NSDateFormatter to explain the date, and I'd like something short but more intuitive than 15/07/10. I think I've seen some formats that will say simply "Today" or "Tomorrow" or the day of the week for subsequent days of the same week. Is there a simple apple-approved way to get this type of date?
Thanks.
If you're targeting iOS 4 or later, you can call [yourFormatter setDoesRelativeDateFormatting:YES]. Otherwise, you'll most likely need a custom subclass. As for days of the week, what jer said.
Ensure you set up your locale with the NSDateFormatter appropriately, and then ask for the weekdaySymbols. This will return an array with the days of the week in the locale you specify.

Change UIDatePicker from 12 hour clock to 24 hour clock and back

I'm sorry to make my first question here a bit of a simple one -- I've spent a day reading the NSLocale and NSCalendar class descriptions but I couldn't see if this was possible.
I have a UIDatePicker in the UIDatePickerModeDateAndTime mode. It is currently displaying date and time according to the user's locale, which is the default behavior.
I would like to be able to offer the option to show the UIDatePicker in either 12-hour or 24-hour time format. Detecting which time format the user is currently using isn't a problem, but I'm not clear on how to change just the time format of UIDatePicker without entirely throwing out the user's locale settings (since the picker also displays the localized days of the week and months). UIDatePicker supports setting its locale and setting its calendar.
So, question one is whether this is something I should be trying to do via NSLocale or NSCalendar, and question two is if anyone can recommend a way to isolate the time format without throwing out the rest of the user's locale settings.
Thanks for any suggestions.
This is not the answer you are looking for, but in Cocoa you could create an NSDateFormatter and attach it to an NSDatePicker (which is an NSControl) using setFormatter. Unfortunately the equivalent iPhone class (UIControl) does not support this yet. I raised a bug with Apple about it and this is a known issue, although they wouldn't tell me if/when they plan to fix/enhance it.
OK, after reading the last two years' worth of others asking the same question here, it seems that there is no way to do this since the UIDatePicker uses the user's country setting instead of the user's locale setting, and that can't be overridden programmatically. I filed a bug.
I have solved this problem by using the user input of AM/PM by initializing another variable as a string of either AM or PM based upon the 12 hour format. The new hour in 24 hour format is put into NSCalendar. To wit:
var hra = 1//ENTER INITIAL HOUR (HH)
var dna = "PM"//ENTER "AM" OR "PM"
if hra <= 12 && dna == "PM"{
hra = hra + 12
}
The variable hra now takes the value of the 24 hour format.