Thursday 15 April 2010

objective c - How can I determine if the current date is within/outside a range of two dates that don't include a year? -



objective c - How can I determine if the current date is within/outside a range of two dates that don't include a year? -

so have object (activity) allow users select start date , expiry date activity.

the user center/centre provides activities public.

they have alternative of making these activities seasonal. illustration activity run feb 01 june 22. utilize current date along bunch of code determine if activity in season or not.

so illustration check if current date 271014 greater start date 020114 , less expiry date 062214. if means date in range.

the issue:

i've had create changes, user must select month , day only. fine until select nov 01 feb 28. these dates in format 1101 , 2802.

without year gives me different results. year have been able determine expiry date feb 28 year after start date , not same year. when working out if current date within start date , expiry date i'd expected results. without year expiry date not greater start date though should be.

what i'm doing

how solve issue? need allow user set start date , expiry. activity show in table view when current date in range.

if expiry date selected activity remain active until expiry date has been reached. if set , expiry date feb 28 , we're in november. same need applies start date too.

would appreciate insight here.

thanks time.

here suggestion (in pseudo-code): convert dates strings in format "mmdd", in example

startdate = "1101" // nov 1 expirydate = "0228" // feb 28 currentdate = "1027" // oct 27

if startdate <= expirydate range within same year , can check current date with

if (startdate <= currentdate && currentdate <= expirydate) ...

otherwise range starts in 1 year , ends in next year, , check with

if (currentdate >= startdate || currentdate <= expirydate) ...

objective-c swift nsdate nsdateformatter nscalendar

No comments:

Post a Comment