Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dates and Times by Example (AltConf 2018)

Dates and Times by Example (AltConf 2018)

Have you ever had a bug that dealt with dates and times? Dealing with time zones, Daylight Saving Time, and the like can make the hair on the back of even the most experienced developer's neck stand up. We all know how to tell time and how calendars work, and yet these bugs are terrifying. Why? Using Swift as a lens to walk through common problems, we’ll explore writing date and time code that’s correct and easy to understand. You’ll leave with an approach to solving calendrical calculations without fear, new tools for handling these problems in your code, and a huge appreciation for the people behind the libraries that make this possible.

Jeff Kelley

June 07, 2018
Tweet

More Decks by Jeff Kelley

Other Decks in Programming

Transcript

  1. About Me • iOS Developer for 10 years • Recently:

    web frontend/middleware using TypeScript • Author of Learn Cocoa Touch for iOS and Developing for Apple Watch Jeff Kelley @SlaunchaMan
  2. About Me • iOS Developer for 10 years • Recently:

    web frontend/middleware using TypeScript • Author of Learn Cocoa Touch for iOS and Developing for Apple Watch Jeff Kelley @SlaunchaMan
  3. About Me • iOS Developer for 10 years • Recently:

    web frontend/middleware using TypeScript • Author of Learn Cocoa Touch for iOS and Developing for Apple Watch Jeff Kelley @SlaunchaMan
  4. Previous Talks • Dates and Times in iOS, AltConf 2014

    • Advanced Dates and Times in Swift, 360|iDev 2017 Jeff Kelley @SlaunchaMan
  5. Quick Recap • A Date is a moment in time.

    • Stop thinking about Date in terms of time zones • When you po a Date, you get something like this: 2018-06-05 20:26:22 +0000 Jeff Kelley @SlaunchaMan
  6. Quick Recap • A Date is a moment in time.

    • Stop thinking about Date in terms of time zones • When you po a Date, you get something like this: 2018-06-05 20:26:22 +0000 - timeIntervalSinceReferenceDate : 549923182.35240304 Jeff Kelley @SlaunchaMan
  7. Formatters • Use them! • We have gotten new formatters

    since NSDateFormatter, check them out to see if they meet your needs. Jeff Kelley @SlaunchaMan
  8. Problems With Solutions This talk will have two main parts:

    problems with solutions, and problems without solutions. The previous example was the first case. Jeff Kelley @SlaunchaMan
  9. Problems Without Solutions It’s 11:55 PM. Your user says, “In

    fifteen minutes, remind me to go to bed.” But there’s a leap second at 11:59:60. Does the timer go off at 12:10:00 AM or 12:09:59 AM? Jeff Kelley @SlaunchaMan
  10. How We Talk About Dates “We entered the timestamps in

    the location’s time zone.” TIMESTAMP 2018-06-07 14:45 Jeff Kelley @SlaunchaMan
  11. How We Talk About Dates TIMESTAMP 2018-06-07 14:45 AT TIMEZONE

    'PDT' TIMESTAMP 2018-06-07 14:45 AT TIMEZONE 'America/ Los_Angeles' Jeff Kelley @SlaunchaMan
  12. More Resources • Date and Time Programming Guide, Apple •

    YourCalendricalFallacyIs.com, Dave DeLong • Chronology, Dave DeLong Jeff Kelley @SlaunchaMan