SlideShare uma empresa Scribd logo
1 de 68
DATE ANDTIME
Odds, Ends, and Oddities
About Me
www.maggiepint.com
@maggiepint
maggiepint@gmail.com
https://xkcd.com/1597/
Like Git:
• Date and time is complicated
• At first, we avoid learning date and time
But also, like Git:
• Date and time makes sense
• Date and time can be fun
5 O'clock Somewhere
PERSPECTIVE
We all see dates and times from different angles
The GlobalTimeline
1 2 3 4 5 6 7 8 9
Point in absolute time
Coordinated UniversalTime (UTC)
• A perspective of the global timeline
• Allows us to keep track of absolute time
• Primary standard by which the world regulates clocks
• Defined precisely by scientific community
• Includes leap seconds
• Has no relationship to geography
• Basically the same as GMT, but GMT is not defined precisely by the scientific
community
LocalTime
• A local time is a perspective of time
• It does not represent a point on the global timeline
• It is usually not a contiguous timeline (DST)
UTC Time:
2016-04-09T14:17:47Z
What we know
• The point in absolute time
• Whether this time is before or after
another point in time
What we don’t know
• Whether it is morning or night
• What day of the week it is
LocalTime:
Saturday,April 9, 2016 9:11 AM
We Know
• It is Saturday
• It is morning
We Don’t Know
• What point this is on the global
timeline
• Whether it is before or after a time
from a different locality
• What the time will be if we add one
hour to this time
TIME ZONES
Uniting Perspectives
Time Zone Basics
• A time zone is a region that observes a uniform standard time
• A time zone is defined by a set of offsets from UTC
• Offsets are typically in one hour intervals, but not always
• Nepal StandardTime is UTC +5:45
• Time zones frequently have multiple offsets
• There are two main resources for time zones
• Internet Assigned Numbers Authority (IANA)
• WindowsTime Zones
• IANA time zones are more widely used, and more accurate
Time Zone: America/Chicago
Politics
• Time zones are inherently political
• Governments change time zones regularly
• Governments change time zones suddenly
• Russia this year is an example of politicians causing time chaos
• http://bit.ly/1SB9TvW
• Morocco reverts to standard time during Ramadan
• Assume nothing
IANATime Zone Libraries
• JavaScript - MomentTimeZone
• http://momentjs.com/timezone/
• .NET – NodaTime
• http://nodatime.org/
• Java 8 + - java.time (native)
• Java 7 - JodaTime
• See Stack Overflow post for more exhaustive list
• http://bit.ly/1RUYuuM
Time Zones are not Offsets!
"2016-04-09T19:39:00-05:00“
This date could be in:
• America/Chicago
• America/Bahia_Banderas
• America/Bogata
• America/Cancun
• America/Cayman
• And more
ASSUMPTIONS
Things we think we know
Assumption
“If you just store everything in UTC, all your
problems will be solved.”
ATableWith Everything in UTC
Show me all the messages for the
business day of April 4th.
I have users in London, and across the United States.
In LondonApril 4th is between 2016-04-03 23:00:00Z and 2016-04-04 22:59:59Z
In MinneapolisApril 4th is between 2016-04-04 05:00:00Z and 2016-04-05 04:59:59Z
Perspectives
• When storing a date, consider the following perspectives
• Absolute time
• Time local to the date’s viewer
• Time local to the date’s originator
2016-04-09T20:18:48-05:00
ISO 8601 Format with Offset
Local Date LocalTime Offset
Why use ISO 8601 format?
• With offset, reflects both local and absolute perspective
• Has unambiguous ordering
• Compare this to 4/10/2016
• In the US this is April 10th
• In the UK this is October 4th
• Helps avoid having to compute local perspective from absolute
during querying
• Supported by nearly all modern databases
• Databases will automatically order in absolute time
Assumption
“If I just store everything in ISO 8601 with an
offset, everything will be fine.”
Future Dates
• Time zones change over time
• In the future, the offset of a scheduled time could change
• Store future dates in local time with a time zone
Assumption
“There are 24 hours in a day, and 365 days in a
year.”
moment('2016-03-12 12:00').add(1, 'day').format('LLL')
"March 13, 2016 12:00 PM"
moment('2016-03-12 12:00').add(24,'hour').format('LLL')
"March 13, 2016 1:00 PM"
moment('2016-02-28').add(365, 'days').format('LLL')
"February 27, 2017 12:00 AM"
moment('2016-02-28').add(1, 'year').format('LLL')
"February 28, 2017 12:00 AM"
As Seen on Stack Overflow
var startHours = 8;
var startMinutes = 30;
var ed = new Date();
var endHours = ed.getHours();
var endMinutes = ed.getMinutes();
var elapsedMinutes = (endHours * 60 + endMinutes) - (startHours * 60 +
startMinutes);
console.log(elapsedMinutes);
Assumption
“Time and date math work in the same way.”
moment('2016-01-01').add(1.5, 'hours').format('LLL')
"January 1, 2016 1:30AM“
moment('2016-01-01').add(1.5, 'days').format('LLL')
"January 3, 2016 12:00 AM"
Time Math vs Date Math
Time math:
• Refers to operations involving hours, minutes, seconds, milliseconds
• Works by incrementing or decrementing the position on the global timeline by the number of
units in question
• Can use fractional units
Date Math:
• Refers to all operations larger than hours – days, months, years, quarters, etc.
• Works by moving places on the calendar
• Cannot be converted to time math
• Cannot use fractional units
Assumption
“All dates and times exist once in all time
zones”
moment('2016-10-16').format('LLL')
October 16, 2016 1:00 AM
Spring Forward in JavaScript
Fall Back in JavaScript
Samoa
• Samoa is very close to the international date line
• Samoa found itself trading more frequently with Australia than America
• Samoa switched sides of the international date line
• December 30 2011 does not exist in Samoan time
Assumption
“The Date object in JavaScript works.”
var a = new Date('2016-01-01');
a.toString();
"Thu Dec 31 2015 18:00:00 GMT-0600 (Central StandardTime)"
var a = new Date('1/1/2016');
a.toString();
"Fri Jan 01 2016 00:00:00 GMT-0600 (Central StandardTime)"
Known JavaScript Date Issues
• DSTTransitions can go both directions
• Months index from zero
• No support for time zones other than user’s local time zone and UTC
• Older browsers know only current DST rules
• Parsing is implementation specific and basically completely broken
• The spec is a disaster
http://codeofmatt.com/2013/06/07/javascript-date-type-is-
horribly-broken/
MOMENT.JS
Quality Date andTime in Javascript
Parsing
• Consistently parses date values according to your expectations
• More than 100 languages supported
• Thousands of options for parse-able formats
• Parse multiple formats if necessary
moment('2016-12-21T13:25:22').format()
"2016-12-21T13:25:22-06:00"
moment('30/04/2016', 'DD/MM/YYYY').format()
"2016-04-30T00:00:00-05:00"
moment('February 25, 2016', 'MMMM DD, YYYY').format()
"2016-02-25T00:00:00-06:00"
moment('octubre 25, 2016', 'MMMM DD, YYYY', 'es').format()
"2016-10-25T00:00:00-05:00"
Formatting
• Highly configurable format options
• Locale based formatting functions
moment().format('MM/DD/YYYY')
"04/26/2016"
moment().format('MMMM D, YYYY hh:mm a')
"April 26, 2016 09:26 pm"
moment().format('LLL')
"April 26, 2016 9:28 PM"
moment().format('L')
"04/26/2016"
moment().locale('en-gb').format('L')
"26/04/2016"
moment().locale('ar').format('LLL')
"٢٦‫أبريل‬ ‫نيسان‬٢٠١٦٢١:٣١"
Sane Math
• Add and subtract any unit
• StartOf/EndOf
• Difference
var a = new Date();
a.setDate(a.getDate() - 5);
moment().subtract(5, 'days');
var d = new Date();
var diff = d.getDate() - d.getDay() + (day == 0 ? -6:1);
d.setDate(diff);
d.setHours(0,0,0,0);
moment().startOf('week')
var d1 = new Date();
var d2 = new Date(01/01/2016);
var months;
months = (d2.getFullYear() - d1.getFullYear()) * 12;
months -= d1.getMonth() + 1;
months += d2.getMonth();
var diff = months <= 0 ? 0 : months;
moment().diff('2016-01-01', 'months');
RelativeTime
moment().subtract(3, 'months').fromNow()
"3 months ago"
moment().subtract(2, 'seconds').fromNow()
"a few seconds ago"
moment().add(4, 'hours').locale('tlh').fromNow()
"loS rep pIq"
Over 100 locales.This is Klingon.
Time Zones (With MomentTimeZone)
moment.tz('2016-04-25T02:30:00Z', 'America/Los_Angeles').format()
"2016-04-24T19:30:00-07:00"
moment.tz('2016-04-25T02:30:00Z', 'Europe/Berlin').format()
"2016-04-25T04:30:00+02:00"
IN SUMMARY
We all know what happens when you assume
CONSIDER ALL PERSPECTIVES
DISTINGUISH BETWEEN LOCAL AND
ABSOLUTETIME
REMEMBER,TIME ZONES CHANGE
RAPIDLY
STORE FUTURE DATES IN LOCALTIME
DISTINGUISH BETWEEN DATE MATH
ANDTIME MATH
DON’TTRUST JAVASCRIPT DATE
USE A QUALITY LIBRARY
MAKE NO ASSUMPTIONS
Be like this guy:
Additional Resources
• Date andTime Fundamentals – Matt Johnson, Pluralsight
• https://www.pluralsight.com/courses/date-time-fundamentals
• Matt Johnson’s Blog
• http://codeofmatt.com/
• LauTaarnskov’s Blog
• http://www.creativedeletion.com/
• NodaTime’s Documentation
• http://nodatime.org/
• Time Programming Fundamentals – Greg Miller CPPCon 2015
• http://bit.ly/1SgO3E0
• Moment.js
• http://momentjs.com/
About Me
www.maggiepint.com
@maggiepint
maggiepint@gmail.com
https://github.com/maggiepint
That Conference Date and Time

Mais conteúdo relacionado

Destaque

Southside Green - Opening Presentation
Southside Green - Opening PresentationSouthside Green - Opening Presentation
Southside Green - Opening Presentation
M. Damon Weiss
 
Documentos 11 horror en la segunda guerra mundial
Documentos 11 horror en la segunda guerra mundialDocumentos 11 horror en la segunda guerra mundial
Documentos 11 horror en la segunda guerra mundial
ANA HENRIQUEZ ORREGO
 

Destaque (19)

Building Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreBuilding Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET Core
 
Got documents Code Mash Revision
Got documents Code Mash RevisionGot documents Code Mash Revision
Got documents Code Mash Revision
 
公開用EU一般データ保護規則への実務対応
公開用EU一般データ保護規則への実務対応 公開用EU一般データ保護規則への実務対応
公開用EU一般データ保護規則への実務対応
 
adaptTo() 2014 - Integrating Open Source Search with CQ/AEM
adaptTo() 2014 - Integrating Open Source Search with CQ/AEMadaptTo() 2014 - Integrating Open Source Search with CQ/AEM
adaptTo() 2014 - Integrating Open Source Search with CQ/AEM
 
Droptrax
DroptraxDroptrax
Droptrax
 
Active Directory Delegation - By @rebootuser
Active Directory Delegation - By @rebootuserActive Directory Delegation - By @rebootuser
Active Directory Delegation - By @rebootuser
 
Big Data Streaming processing using Apache Storm - FOSSCOMM 2016
Big Data Streaming processing using Apache Storm - FOSSCOMM 2016Big Data Streaming processing using Apache Storm - FOSSCOMM 2016
Big Data Streaming processing using Apache Storm - FOSSCOMM 2016
 
Youth programs provide a future for the sport
Youth programs provide a future for the sportYouth programs provide a future for the sport
Youth programs provide a future for the sport
 
Stream processing using Apache Storm - Big Data Meetup Athens 2016
Stream processing using Apache Storm - Big Data Meetup Athens 2016Stream processing using Apache Storm - Big Data Meetup Athens 2016
Stream processing using Apache Storm - Big Data Meetup Athens 2016
 
De la féminisation à la débinarisation
De la féminisation à la débinarisation De la féminisation à la débinarisation
De la féminisation à la débinarisation
 
Modernizing Applications with Microservices and DC/OS (Lightbend/Mesosphere c...
Modernizing Applications with Microservices and DC/OS (Lightbend/Mesosphere c...Modernizing Applications with Microservices and DC/OS (Lightbend/Mesosphere c...
Modernizing Applications with Microservices and DC/OS (Lightbend/Mesosphere c...
 
REST: From GET to HATEOAS
REST: From GET to HATEOASREST: From GET to HATEOAS
REST: From GET to HATEOAS
 
Southside Green - Opening Presentation
Southside Green - Opening PresentationSouthside Green - Opening Presentation
Southside Green - Opening Presentation
 
Tendencias del marketing industrial 2016. parte 1
Tendencias del marketing industrial 2016. parte 1Tendencias del marketing industrial 2016. parte 1
Tendencias del marketing industrial 2016. parte 1
 
DOBRÁ ZNAČKA PRO VEŘEJNOU SLUŽBU
DOBRÁ ZNAČKA PRO VEŘEJNOU SLUŽBUDOBRÁ ZNAČKA PRO VEŘEJNOU SLUŽBU
DOBRÁ ZNAČKA PRO VEŘEJNOU SLUŽBU
 
Evoking excellence through agile coaching
Evoking excellence through agile coachingEvoking excellence through agile coaching
Evoking excellence through agile coaching
 
Why vREST?
Why vREST?Why vREST?
Why vREST?
 
Infographic: Adobe State of Create 2016 Study
Infographic: Adobe State of Create 2016 StudyInfographic: Adobe State of Create 2016 Study
Infographic: Adobe State of Create 2016 Study
 
Documentos 11 horror en la segunda guerra mundial
Documentos 11 horror en la segunda guerra mundialDocumentos 11 horror en la segunda guerra mundial
Documentos 11 horror en la segunda guerra mundial
 

Semelhante a That Conference Date and Time

Java 8 Date and Time API
Java 8 Date and Time APIJava 8 Date and Time API
Java 8 Date and Time API
Sualeh Fatehi
 

Semelhante a That Conference Date and Time (20)

Data Wrangling: Working with Date / Time Data and Visualizing It
Data Wrangling: Working with Date / Time Data and Visualizing ItData Wrangling: Working with Date / Time Data and Visualizing It
Data Wrangling: Working with Date / Time Data and Visualizing It
 
A JSR-310 Date: Beyond JODA Time
A JSR-310 Date: Beyond JODA TimeA JSR-310 Date: Beyond JODA Time
A JSR-310 Date: Beyond JODA Time
 
Fun times with ruby
Fun times with rubyFun times with ruby
Fun times with ruby
 
Java 8 date & time api
Java 8 date & time apiJava 8 date & time api
Java 8 date & time api
 
"Working with date and time data in .NET", Jon Skeet
"Working with date and time data in .NET", Jon Skeet"Working with date and time data in .NET", Jon Skeet
"Working with date and time data in .NET", Jon Skeet
 
The State of Time in OpenHistoricalMap
The State of Time in OpenHistoricalMapThe State of Time in OpenHistoricalMap
The State of Time in OpenHistoricalMap
 
Brand new Date and Time API
Brand new Date and Time APIBrand new Date and Time API
Brand new Date and Time API
 
Brand New Date and Time API
Brand New Date and Time APIBrand New Date and Time API
Brand New Date and Time API
 
SQL Server Temporal Tables
SQL Server Temporal TablesSQL Server Temporal Tables
SQL Server Temporal Tables
 
Lesson 05 - Time in Distrributed System.pptx
Lesson 05 - Time in Distrributed System.pptxLesson 05 - Time in Distrributed System.pptx
Lesson 05 - Time in Distrributed System.pptx
 
Timezone Mess
Timezone MessTimezone Mess
Timezone Mess
 
Java 8 Date and Time API
Java 8 Date and Time APIJava 8 Date and Time API
Java 8 Date and Time API
 
Searching over the past, present and future
Searching over the past, present and futureSearching over the past, present and future
Searching over the past, present and future
 
Zombie Time - JSR 310 for the Undead
Zombie Time - JSR 310 for the UndeadZombie Time - JSR 310 for the Undead
Zombie Time - JSR 310 for the Undead
 
Postgres Vision 2018: Five Sharding Data Models
Postgres Vision 2018: Five Sharding Data ModelsPostgres Vision 2018: Five Sharding Data Models
Postgres Vision 2018: Five Sharding Data Models
 
Java 8 Date-Time API
Java 8 Date-Time APIJava 8 Date-Time API
Java 8 Date-Time API
 
Time Series Forecasting Using TBATS Model.pptx
Time Series Forecasting Using TBATS Model.pptxTime Series Forecasting Using TBATS Model.pptx
Time Series Forecasting Using TBATS Model.pptx
 
Programming in the 4th Dimension
Programming in the 4th DimensionProgramming in the 4th Dimension
Programming in the 4th Dimension
 
Using Time Window Compaction Strategy For Time Series Workloads
Using Time Window Compaction Strategy For Time Series WorkloadsUsing Time Window Compaction Strategy For Time Series Workloads
Using Time Window Compaction Strategy For Time Series Workloads
 
Calendar options in m365
Calendar options in m365Calendar options in m365
Calendar options in m365
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Último (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

That Conference Date and Time