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.

8d92e9730c561c120200f34e7e50ed46?s=128

Jeff Kelley

June 07, 2018
Tweet

Transcript

  1. Dates and Times by Example 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. 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
  5. I still struggle with date and time issues. Jeff Kelley

    @SlaunchaMan
  6. Previous Talks • Dates and Times in iOS, AltConf 2014

    • Advanced Dates and Times in Swift, 360|iDev 2017 Jeff Kelley @SlaunchaMan
  7. 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
  8. 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
  9. Formatters • Use them! • We have gotten new formatters

    since NSDateFormatter, check them out to see if they meet your needs. Jeff Kelley @SlaunchaMan
  10. Demo: Formatting Intervals Jeff Kelley @SlaunchaMan

  11. Problems With Solutions Jeff Kelley @SlaunchaMan

  12. 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
  13. Time Zones and Locations Jeff Kelley @SlaunchaMan

  14. None
  15. Demo: Time Zones and Locations Jeff Kelley @SlaunchaMan

  16. Demo: Time Zone-Agnostic Notifications Jeff Kelley @SlaunchaMan

  17. Problems Without Solutions Jeff Kelley @SlaunchaMan

  18. Problems Without Solutions What if there's no “right answer?” Jeff

    Kelley @SlaunchaMan
  19. 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
  20. Problems Without Solutions Year-Over-Year Graphs Jeff Kelley @SlaunchaMan

  21. Problems Without Solutions Year-Over-Year Graphs Jeff Kelley @SlaunchaMan

  22. Problems Without Solutions Year-Over-Year Graphs Jeff Kelley @SlaunchaMan

  23. Problems Without Solutions Month-over-Month Graphs Jeff Kelley @SlaunchaMan

  24. Problems Without Solutions Week-over-Week Graphs Jeff Kelley @SlaunchaMan

  25. How We Talk About Dates “We entered the timestamps in

    the location’s time zone.” TIMESTAMP 2018-06-07 14:45 Jeff Kelley @SlaunchaMan
  26. 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
  27. Demo: Date Ranges with DateInterval Jeff Kelley @SlaunchaMan

  28. More Resources • Date and Time Programming Guide, Apple •

    YourCalendricalFallacyIs.com, Dave DeLong • Chronology, Dave DeLong Jeff Kelley @SlaunchaMan
  29. Thank You! Jeff Kelley, jeff@detroitlabs.com @SlaunchaMan on Twitter