ios - Swift : Checking if 2 NSDates are the same -
really simple one, sure bug in swift. trying check if 2 nsdates same. statement never passes thought printout below
println("\(statistics.startdate) \(healthobject.date)") if healthobject.date.isequaltodate(statistics.startdate) { healthobject.flights = int(quantity.doublevalueforunit(hkunit.countunit())) println(int(quantity.doublevalueforunit(hkunit.countunit()))) }
2015-03-30 13:56:50 +0000 2015-03-30 13:56:50 +0000
2015-03-30 13:56:50 +0000 2015-03-31 13:56:50 +0000
2015-03-31 13:56:50 +0000 2015-03-30 13:56:50 +0000
2015-03-31 13:56:50 +0000 2015-03-31 13:56:50 +0000
solution pointed out 1 awesome people replied, dates same until sub second level. odd part is, these values coming healthkit
what works me in ios8 is:
if let dif = calender?.comparedate(statistics.startdate, todate: healthobject.date, tounitgranularity: nscalendarunit.secondcalendarunit) { println(int(quantity.doublevalueforunit(hkunit.countunit()))) println("\(statistics.startdate) \(healthobject.date)") healthobject.flights = int(quantity.doublevalueforunit(hkunit.countunit())) }
the simplest way check if dates equal use nsdate.isequaltodate() method.
or
nscalendar.currentcalendar().comparedate(date1, todate: date2, tounitgranularity: nscalendarunit.calendarunitsecond)
if using quite bit of date arithmetic check this library.
Comments
Post a Comment