When is the 3901 final exam? What is the date today?
How many seconds are in an hour? How many hours are in a day? How many days are in a year?
Computer Science and Engineering The Ohio State University
Copyright By PowCoder代写 加微信 powcoder
Date and Time Handling
Computer Science and Engineering College of Engineering The Ohio State University
Interval vs Point
Different questions:
Computer Science and Engineering The Ohio State University
Answering “how long?” is easy
Count the number of elapsed seconds Easy to code
Answering “when?” is tricky
4 pm (May 2, 2017) is not sufficient Meaning depends on geolocation!
Even dates (May 2nd) have this problem
“How long did it take to run 5k?” “When is our final exam?”
Solving Time/Place Problem
Computer Science and Engineering The Ohio State University
Fix one place on earth, and use that location’s time We agreed (in 1884): Greenwich, England
Same location as used for longitude “Prime Meridian” of longitude (ie 0°)
Aside: What are the co-ordinates of the oval? Once called “ Time” (GMT)
Now called “Coordinated Universal Time” (UTC) Example
CSE 3901 final exam is at 7 pm on May 2, 2017 So why does it say 3 pm on SIS?
Time Zones
People want their clocks to show 12:00 when the sun is high in the sky
Solution: Time zones
Geographic region that uses the same offset from defined
Abbreviations
EST = UTC-5:00 (“Standard”, i.e. winter)
EDT = UTC-4:00 (“Daylight savings” summer) To report a time, append time zone
2017-05-02 15:00:00 EDT 2017-05-02 15:00:00 UTC-4:00 2017-05-02 19:00:00 UTC
Computer Science and Engineering The Ohio State University
Notation: Encoding Date/Time
Computer Science and Engineering The Ohio State University
Computer scientists understand the importance of representation/encoding
Big Endian
year-month-day hour:minute:second 2017-05-02 15:00:00
Benefit: lexicographic = chronological
Start at 0, not 1
Non-CS folks call this a “24-hour clock”! CS folks call this… normal
00:00 is midnight, 12:00 is noon Benefit: Avoids am/pm ambiguities
Mixing Intervals and Points
Computer Science and Engineering The Ohio State University
Mapping between these is tricky E.g. run a task every day at 9 am
Naïve solution: java.util.Timer’s schedule
schedule (TimerTask t, Date first,
long period)
Period is an interval (number of
milliseconds)
schedule(job, noonToday, 86400000);
Mixing Intervals and Points
Computer Science and Engineering The Ohio State University
Mapping between these is tricky E.g. run a task every day at 9 am
Naïve solution: java.util.Timer’s schedule
schedule (TimerTask t, Date first,
long period)
Period is an interval (number of milliseconds) schedule(job, noonToday, 86400000);
Not every day has 24 hrs!
Daylight savings ==> a day can be 24, 23, or 25 hours long
From Intervals to Points
Computer Science and Engineering The Ohio State University
Measure interval from a fixed point
Called “epoch”
Needed for both date (BC/AD) and time
Unix: chose Jan 1, 1970
long time_t, count of elapsed seconds
What time is it? Approx. 1,492,015,000 See http://www.unixtimestamp.com
End of the World
Computer Science and Engineering The Ohio State University
From Intervals to Points
Computer Science and Engineering The Ohio State University
Measure interval from a fixed point Called “epoch”
Needed for both date (BC/AD) and time Unix: chose Jan 1, 1970
long time_t, count of elapsed seconds What time is it? Approx. 1,492,015,000
See http://www.unixtimestamp.com Stored as a (signed!) 32-bit integer
“max time” = 232-1 = 2.1 billion = 68 years! Will overflow on Jan 19, 2038
Solution: use 64 bit!
Postpones the problem for 290 billion years…
This hour has ?? minutes…
Computer Science and Engineering The Ohio State University
Seconds, Minutes, Hours, Days
Computer Science and Engineering The Ohio State University
Days do not divide years evenly About 365.242199 days/year
But seconds do divide days evenly! Exactly 24 * 60 * 60 = 86,400 s/day
Days & years are set independently by nature
Seconds are our invention How long is a second?
Defined to be 1/86,400th of a day
SI second = 9,192,631,770 oscillations of a caesium- 133 atom (at rest, sea level, 0 Kelvin)
Just one problem… how long is a day?
Problem: Solar / Sidereal Day
Computer Science and Engineering The Ohio State University
Problem: Apparent / Mean Solar
Computer Science and Engineering The Ohio State University
We are closest to the sun in winter Speed of orbit distance to sun
Also, Earth’s axis is tilted
Sun (appears to) move along ecliptic
But Earth rotates along celestial equator
Result: Each apparent solar day (24 hrs?) varies in length!
Can be +/- 30 seconds of average length Even worse: Variation is correlated!
Long days are consecutive during the year
Difference (local noon vs watch) accumulates Result: Net difference of +/- 15 minutes
Equation of Time
Computer Science and Engineering The Ohio State University
Do We Care?
Computer Science and Engineering The Ohio State University
The equation of time lets you correctly convert time to/from position of sun
At what time will be “local noon” today?
See: www.timeanddate.com/sun
This only matters if you care about the exact position of
the sun any given day!
Eg sundials and sextants
So (mostly) no one cares
All we need is average length of full day
A “mean solar day”
Horizontal axis in graph of equation of time Measure it, super accurately, then divide by 86,400
Now For the Really Bad News
Computer Science and Engineering The Ohio State University
The Earth is Slowing Down
Computer Science and Engineering The Ohio State University
Planet has been slowing down (and will continue to slow down)
Today’s “mean solar day” is longer than it was 200 years ago!
We use the mean solar day of 1750-1892 (averaged)
Bad news: There are a bit more than 86,400 SI seconds / mean solar day Really bad news: We can’t predict the size of this effect very far into future
Leap Seconds
Mean solar day is longer than 86400 SI seconds Tidal forces have slowed the rotation of the earth
Must correct clock time to stay synched with solar days
Leap second: 1 second insertion/deletion Irregular occurrence, UTC decides
Based on observation, impossible to predict Since 1972, there have been 27 additions, no deletions
Most recent: Dec 31, 2016 (an addition)
Computer Science and Engineering The Ohio State University
Leap Second Episodes
Computer Science and Engineering The Ohio State University
1 minute ≠ 60 seconds
Computer Science and Engineering The Ohio State University
Addition/removal occurs during the last
minute of Dec 31 or Jun 30
Those minutes have 61 or 59 seconds! 23:59:58, 23:59:59, 23:59:60, 00:00:00…
Screen capture of the clock at time.gov during a leap second:
More Complications
Computer Science and Engineering The Ohio State University
GPS satellites don’t reset their clocks
GPS time was equal to UTC time in 1980 Since then, has missed 18 leap seconds http://leapsecond.com/java/gpsclock.htm
Unix time decrements during leap second
Monotonic timer provided by NTP protocol Not all countries have adopted UTC Leap seconds will become more frequent
Proposals to abolish, replace with leap
GMT vs UT1 vs UTC
GMT: Greenwich mean time Antiquated: Should not be used today
UT1: Universal time
Time at prime meridian
Determined by celestial movements
TAI: Atomic time
Was equal to UT1 in 1958 Ticks in SI seconds
UTC: Universal Coordinated Time
Ticks in SI seconds, like TAI Periodically modified to match UT1
Computer Science and Engineering The Ohio State University
And we care because…
Computer Science and Engineering The Ohio State University
Intervals vs points
Computer Science and Engineering The Ohio State University
Interval between 2 points is hard
# days / year can vary
# hours / day can vary
# seconds / minute can vary
Standardization
Mean solar day, SI seconds
They don’t match: need leap seconds
UT1, UTC, TAI
Intervals are easy, points are tricky Unix time: Seconds from 01/01/1970 Date/time is coupled to geolocation
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com