Time

From Braindump
Jump to navigation Jump to search

Timeanddate.com

https://timeanddate.com/

Timezone date

TZ=Europe/Helsinki
UTC+3h is UTC+2h + summer time 
EET+daylight saving time = EEST

https://www.iana.org/time-zones

http://dschepler.github.io/lfs-dpkg/chapter06/tzdata.html

The beginning of time keeping

1493 Leonardo da Vinci Pendulum
1582 Galileo Galilei
1656 Christiaan Huygens Pendulum clock
1714 Jeremy Tacker Chronometer
1730 John Harrison Marine Chronometer Langitude could be measured for marine navigation by keeping exact time
1847 Royal Observatory GMT Time zone were introduced when rail travel spanned multiple timezones
1952 ITU-R TAI = UT1 = UTC UT1 observed solar time

TAI is international atomic time. UT + leapseconds

1958 TAI = UT2 Standard time, observed v.s. coordinated.

UTC Coordinated Universal Time is an atomic time scale designed to approximate Universal Time. UTC differs from TAI by an integral number of seconds TAI International Atomic Time (primary realisation of Terrestrial Time)

1967 BIPM 13th General Conference on Weights and Measures

Cs-133:9 192 631 770 cycles of microwave light absorbed or emitted by the hyperfine transition of cesium-133 atoms in their ground state undisturbed by external fields.

1977 ET Ephemeris Time

1.0003725 TT = 1977 January 1.0000000 TAI

Time Formats

GMT is Greenwich Mean Time
Z   is Zulutime
UT1 observed solar time
TAI is international atomic time. UT + leapseconds
UTC is Universal Coordinated Time
ET - TAI = 32.184 seconds
ET - UT = ΔT
TT Terrestrial Time (new ET) a coordinate time scale at Earth's surface
UT Universal Time
UT is based on sidereal time, but with a scaling factor and other adjustments to make them closer to solar time.
UT = UTC / UT1
UT0 is the rotational time observed as the diurnal motion of stars or extraterrestrial radio sources.
UT1 is computed by correcting UT0 for the effect of polar motion
UT2 is a smoothed version of UT1, filtering out periodic seasonal variations, hardly in use
UT2R is a smoothed version of UT1, incorporating both the seasonal corrections of UT2 and the tidal corrections of UT1R
SI seconds (by BIPM)
UTC (by ITU-R)
BIH/IERS is responsible for leap seconds 

UNIX TIME seconds since 0:00 1 January 1970

The "posix" version is based on the Coordinated Universal Time (UTC).
The "right" version is based on the International Atomic Time (TAI), and it includes the leap seconds.

Bulletin on the corrections between UTC and TAI

http://hpiers.obspm.fr/iers/bul/bulc/bulletinc.dat

from 2017 January 1, 0h UTC, until further notice : UTC-TAI = -37 s

https://hpiers.obspm.fr/eoppc/bul/bulc/Leap_Second.dat

Bulletin T on difference between UTC and UTC/NIST (synchronization delay/deviation)

https://www.bipm.org/en/time-ftp/other-products

Programming Language

ISO 8601 Date Formats, 2024-12-13

2024-02-01T22:38:10−07:00

https://www.rfc-editor.org/rfc/rfc3339.html


UNIX

date %y%m%c

Unix Time seconds since January 1970

C

Java: DateTime, Joda

https://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html

JavaScrypt

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

MYSQL / MARIADB

Timestamp

https://docs.oracle.com/cd/E17952_01/mysql-5.7-en/date-and-time-functions.html

Oracle

Microsoft Excel

https://support.microsoft.com/en-us/office/date-function-e36c0c8c-4104-49da-ab83-82328b832349

Why circle 360, 24 timezones

The world turns around it's axis 365 times before it makes a circle around the sun.1 degree per day. Babylonians used base 60 and 6x 60 = 360 so it's neatly divisable.

https://www.iflscience.com/why-are-there-360-degrees-in-a-circle-instead-of-something-useful-like-100-68919


24-hour per day ancient Egyptians who divided day-time into 10 hours they measured with devices such as shadow clocks, and added a twilight hour at the beginning and another one at the end of the day-time.

https://www.abc.net.au/science/articles/2011/11/15/3364432.htm

Summer time

To increase the hours of sunlight in the evening, summertime shifts the clock an hour forward in the sprint time and returns to normal in autumn, but moving an hour backwards.

This is a stupid habit which could have been easily accomplished by agreeing to shift starting times of certain events, rather than messing around with the clock. For instance go to school at 8:00 in the summer and 8:30 in the winter. With modern communication and technology it should be easy to spread out the peaks by better planning. But no! My microwave doesn't know what time it is, my radio controlled clocks can't hear frankfurt that well and clocks are now confused. Working with different timezones where diffent sumertime begin and endtimes are used and shift on the southern hemisphere to a different directions, makes me jetlagged in my own home.

Summer time is stupid. Stop shifting the clock and agree that in spring we get up one hour earlier.

MST mean solar time

The length of the mean solar day is increasing due to the tidal acceleration of the Moon by Earth, and the corresponding deceleration of the Earth by the Moon.

1820 86400 Seconds
+1.4 msec / 100 years
+1.7 msec / 100 years

Mean Sidereal measured against a far away star. Time mean sidereal day is about 23 h 56 m 4.1 s in length

Computer Clock

Computers have a hardware clock for longtime clock keeping and the CPU keeps track of the software clock which is used in application to tell time. The software clock and hardware clock need to be calibrated, so it needs an external clock source.

My clock was running horribly wrong on my brand new computer. It's not a weak BIOS battery and it's not because it's a brand new AMD64. Heat will make clocks 'wobble' a bit, but the real reason was that I should have calibrated the clock. NTP will not correct clocks that are off by more than 500ms / minute. (or was it 500ms)

/etc/init.d/ntp stop
ntpdate stampertje.islief.com
hwclock --systohc
adjtimex -a
/etc/init.d/ntp start

Which clock?

An RTC / realtime hardware clock runs even when the computer is switched off. In the CPU a system clock loads the time from the hardware clock on startup, and updates the hardware clock on shutdown. NTP clocks on the internet provide a reliable time reference, some are directly linked to an atom clock. GPS satellites send precise time information and they have onboard atom clocks.

Hardware clock

http://support.ntp.org/bin/view/Support/KnownOsIssues

There are a few different available hardware clocks in modern PC's. The linux kernel will use one as the clocksource for interupts and also will use one system clock as the source.

cat /sys/devices/system/clocksource/clocksource0/current_clocksource
acpi_pm
cat /sys/devices/system/clocksource/clocksource0/available_clocksource
tsc hpet acpi_pm jiffies 

The clocksource can be selected in the kernel options at bootup, so you can add clocksource to the kernel options.

vi /etc/default/grub.conf
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash clocksource=hpet"
update-grub

The hardwareclock can be read or written from/to the systemclock using

hwclock --systohc
hwclock --hctosys

The systemclock is updated every tick. A kernel generates by default roughly 100 ticks/second. To enhance the precision, the clock can be synchronized to the correct number of ticks and in my case the clock is always too slow, so I set the tick to 10003 which means that my system clock is not drifting as much as before. I previously incorrectly set the tick to 9700 causing a huge drift. adjtimex can calculate the difference between the systemclock and the hardware clock and will estimate what the tick should be. This is a very coarse setting, which can be fine tuned using NTP.

To print the current tick and freq

adjtimex -p

To adjust the tick / freq

adjtimex -a
/etc/init.d/adjtimex restart
/etc/default/adjtimex
TICK=100003
FREQ=4007068

Once the tick has been adjusted and NTP is working the systemclock will be more accurate than the hardware clock. So the drift rate of the hardware clock will be calculated and stored. At startup it is calculated how much time the hardware clock has run undisciplined and the clocks will be corrected by the drift rate calculation.

cat /etc/adjtime

Ethernet TSN

https://en.wikipedia.org/wiki/Time-Sensitive_Networking

NTP

https://gist.github.com/mutin-sa/eea1c396b1e610a2da1e5550d94b0453

NIST runs NTP servers, most are UTC +/- a deviation in nanoseconds. 2 NTP servers report UT1.

https://www.time.gov/

The NIST servers will compute UT1 time by adding the DUT1 value for any MJD to UTC(NIST). The value used for DUT1 will be the value determined by http://www.iers.org

The NTP daemon will use clocksources from the internet to dicipline the system clock. it will first poll the time servers every 64 seconds until it has enough data to check less frequently (every 11 minutes). After a few polls NTP decides which clocksources are reliable (+) and which one it selects as the best (*) it will use. NTP will then slew the clock into the correct time, so a clock which is running 500ms fast will be slowly brought back to the correct time. The longer a clock is disciplined by NTP the more accurate it will be. network traffic will cause a delay between the client and the server, because the network latency increases, which will decrease accuracy. The ntp drift is stored in the driftfile so that the drift can be monitored.

Chrony

https://ubuntu.com/server/docs/how-to-serve-the-network-time-protocol-with-chrony

chronyc makestep
chronyc sources
chronyc sourcestats
chronyc serverstats
chronyc tracking
chronyc clients
chronyc add server ntp.dnafinland.fi
chronyc ntpdata

Chrony pools

A pool is a list of servers listed by DNS.

https://www.vttresearch.com/fi/palvelut/suomen-aika-ntp-palvelu

server time.mikes.fi

https://apps.db.ripe.net/db-web-ui/query?bflag=false&dflag=false&rflag=true&searchtext=194.100.49.139&source=RIPE

https://lg.telia.net/?type=bgp&router=fi-hkitm-asbr1.fi&address=194.100.49.139

sidn time.nl

pool ntp.time.nl

nist time.nist.gov

pool time.nist.gov

time.cloudflare.com

pool time.cloudflare.com

https://developers.google.com/time/smear

time.google.com

pool time.google.com

https://aws.amazon.com/blogs/aws/look-before-you-leap-the-coming-leap-second-and-aws/

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html

time.aws.com

pool time.aws.com

IPv4:169.254.169.123

IPv6: fd00:ec2::123 (Nitro only)

https://tf.nist.gov/tf-cgi/servers.cgi

NTS

Authenticated NTP RFC 8915 https://fedoramagazine.org/secure-ntp-with-nts/

server sth1.nts.netnod.se nts iburst

server sth2.nts.netnod.se nts iburst

https://blog.cloudflare.com/secure-time

https://www.netnod.se/knowledge-base/What-is-Network-Time-Security-NTS

https://fedoramagazine.org/secure-ntp-with-nts/

https://safran-navigation-timing.com/how-to-protect-your-ntp-server-from-cyberattacks/

AWS and Google clock slewing

for the TAI correction, the AWS and Google NTP services slew the clock so the change is smeared out over a day, otherwise the clock could reach 23:59:60, which some applications (databases mainly) may not be able to cope.

Aliyun NTP

https://help.aliyun.com/zh/ecs/user-guide/alibaba-cloud-ntp-server

IPv6

https://www.iana.org/assignments/ipv6-multicast-addresses/ipv6-multicast-addresses.xhtml

FF0X::101 	Network Time Protocol (NTP)
0 	Reserved
1 	Interface-Local scope
2 	Link-Local scope
3 	Realm-Local scope
4 	Admin-Local scope
5 	Site-Local scope
6-7 	Unassigned
8 	Organization-Local scope
9-D 	Unassigned
E 	Global scope
F 	Reserved

MRTG

http://satsignal.eu/ntp/NTPandMRTG.html

https://store.uputronics.com/index.php?route=product/product&product_id=92

chrony can step the clock on the first 3 updates if the clock is off by more than one second. When the system doesn't have an RTC clock, this can be useful

makestep 1.0 3

When the system does have an RTC clock, chrony can sync the time

rtcsync

OpenNTP

ntpq -np
cat /var/lib/ntp/ntp.drift 
ntpdc -c kerninfo

NTP starting up (state 4) and not diciplining the clock yet (unsync)

pll offset:           -0.063174 s
pll frequency:        -2.889 ppm
maximum error:        0.076516 s
estimated error:      1.6e-05 s
status:               0040  unsync
pll time constant:    4
precision:            1e-06 s
frequency tolerance:  500 ppm

NTP operational (state 6) and the clock in a phase locked loop (pll)

pll offset:           -0.074309 s
pll frequency:        -4.266 ppm
maximum error:        0.027339 s
estimated error:      0.027506 s
status:               0001  pll
pll time constant:    6
precision:            1e-06 s
frequency tolerance:  500 ppm

root@sneezy:~# ntpq -np

    remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+192.168.1.2     194.100.100.141  3 u   35   64  377    1.299  -392.16  81.343
*193.180.251.38  192.36.144.22    2 u   33   64  377  187.899  -314.91 141.803
+82.118.208.35   213.203.238.82   3 u   36   64  377  154.986  -330.89 153.852
/etc/dhcp3/dhclient.conf
/etc/ntp.conf.dhcp
/etc/ntp.conf
server 192.168.1.2
restrict -4 default kod notrap nomodify nopeer noquery
/var/lib/ntp/ntp.drift
ntpq -np
ntpdate 192.168.1.2
http://www.ntp.org/ntpfaq/NTP-s-trouble.htm

Windows Time

https://docs.microsoft.com/en-us/windows-server/networking/windows-time-service/windows-time-service-tools-and-settings

ms-sntp
net stop w32time
w32tm /unregister
w32tm /register
net start w32time
w32tm /resync
w32tm /config /manualpeerlist:"10.0.0.5,0x8 ntp.dnafinland.com,0xa" /syncfromflags:manual /update
w32tm /stripchart /computer:time.windows.com /dataonly /samples:5
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\w32time\Parameters\NtpServer

This seems to exist, but is not actually chosen?

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers

Android

platform-tools/adb shell

settings put global ntp_server 10.0.0.5 settings get global ntp_server

settings put global auto_time 0 settings put global auto_time 1 settings get global auto_time

GPS Time

A sync source are the 31 31 operational GPS satellites. They all have a cesium or rubidium atomic clock on board and provide. Not all GPS receivers export a PPS pulse per second which can be used by the GPSD to synchronize to NTPD, the ones that do can have different accuracy based on the gps chip and the mode used. The generic NMEA in one line ASCII is less accurate than any propitiatory binary protocol.

ntpd will use a pseudo-ip address 127.127.1.34 which is a local loopback address, as network socket to the gps driver (gpsd)

In 2010 I bought an BU-353 for 65 Euro's. It contains the popular SiRF_Star_III chip, but it has no pulse per second, so I can't use it as sync source.

./configure --prefix=/usr --disable-garmin --enable-pps-on-cts --disable-evermore --disable-navcom --disable-ashtech --disable-itrax --disable-earthmate --disable-tripmate --disable-fv18 --disable-tsip --disable-ntrip --disable-rtcm104
gpsd -nN -D 5 /dev/ttyUSB0
gpsd -nN /dev/ttyUSB0

gpsctl -b
gpsctl: /dev/ttyUSB0 identified as SiRF binary GSW3.2.4_3.1.00.12-SDK003P1.00a  at 4800
gpsctl: /dev/ttyUSB0 identified as SiRF-II binary at 4800
http://wiki.openstreetmap.org/index.php/User:Dean_Earley/SiRF_Star_III
http://www.usglobalsat.com/downloads/SiRF_Binary_Protocol.pdf
http://www.mr-lee-catcam.de/BINARY/EM406a-datasheet.pdf

Mmmmh, this EM-406 looks like the stuff I saw when I disassembled the BU-353 (HA! those pins where really flimsy. That should teach me not to just pull them when drunk and trying to squeeze them back backwards =) ) ... do I have PPS on pin 6 EM-406a or a PPS-less model EM-406? and where does the PL-2303 RS232-USB converter come in to play??

http://www.usglobalsat.com/download/46/em406a_ug.pdf

Beitan BN-280

In 2019 I bough a Beitan BN-280 with a U-Blox M8N chip with a PPS pulse per second line. I used an arduino uno with SoftwareSerial on pin 10 and 11 to the gps chip. http://arduino.cc/en/Reference/SoftwareSerial

https://maker.pro/raspberry-pi/tutorial/how-to-use-a-gps-receiver-with-raspberry-pi-4

https://austinsnerdythings.com/2021/04/19/microsecond-accurate-ntp-with-a-raspberry-pi-and-pps-gps/

https://katron.org/blog/2021/10/raspberry-pi-gps/

https://www.qso.com.ar/datasheets/Receptores%20GNSS-GPS/BN-280%20GPS%20Module%20Datasheet.pdf

1 PPS
2 GND
3 TX
4 RX
5 VCC 3 to 5V

https://www.u-blox.com/en/product/neo-m8-series#tab-documentation-resources

Through U-Center and the NMEA set it can be tested and configured on windows. It's also possible to switch to U-Blox binary

GPS Commands

setSerialPort
$PSRF100,0
$PSRF100,0,38400,8,1,0*0C
*switch to binary ??
$PASHQ,RI
Debug On
$PSRF105,1*3E
Debug Off
$PSRF105,0*3F
Enable PowerSave
$PSRF150,0,300,1000,1*10
Disable Trickle
$PSRF150,0,1000,1000,0*23
Enable SBAS(WAAS/EGNOS)
$PSRF151,01*0F
Disable SBAS(WAAS/EGNOS)
$PSRF151,00*0E

Roughtime

tlsdate was a parasitic method of retrieve an approximate initial time from tls servers. Since TLS 1.3, the server hello is optional and the server may not tell the time

A new initiative is Google Roughtime, with Cloudflare documenting how to use it in a blog and with a GOLANG code, (rust and java clients exist)

https://datatracker.ietf.org/doc/draft-ietf-ntp-roughtime/07/

git clone https://github.com/cloudflare/roughtime
go get -u github.com/cloudflare/roughtime
go install github.com/cloudflare/roughtime...
getroughtime -ping roughtime.cloudflare.com:2002 -pubkey gD63hSj3ScS+wuOeGrubXlq35N1c5Lby/S+T7MNTjxo=
go run main.go -ping roughtime.cloudflare.com:2002 -pubkey gD63hSj3ScS+wuOeGrubXlq35N1c5Lby/S+T7MNTjxo=
dig TXT roughtime.cloudflare.com | grep -oP 'TXT\s"\K.*?(?=")'
go run main.go -ping roughtime.cloudflare.com:2002 -pubkey gD63hSj3ScS+wuOeGrubXlq35N1c5Lby/S+T7MNTjxo=
go run main.go -ping roughtime.dnov.se:2002 -pubkey hlKAFAeU+xDZ1+9eVgrXel+m3sRiSlzoqCsqL9WoRB0=
go run main.go -ping roughtime.int08h.com:2002 -pubkey AW5uAoTSTDfG5NfY1bTh08GUnOqlRb+HVhbJ3ODJvsE=
go run main.go -ping roughtime.se:2002 -pubkey S3AzfZJ5CjSdkJ21ZJGbxqdYP/SoE8fXKY0+aicsehI=
go run main.go -ping time.0xt.ca:2002 -pubkey iBVjxg/1j7y1+kQUTBYdTabxCppesU/07D4PMDJk2WA=
go run main.go -ping roughtime.chainpoint.org:2002 -pubkey bbT+RPS7zKX6w71ssPibzmwWqU9ffRV5oj2OresSmhE=
go run main.go -ping roughtime.sandbox.google.com:2002 -pubkey etPaaIxcBMY1oUeGpwvPMCJMwlRVNxv51KK/tktoJTQ=
go run main.go -ping ticktock.mixmin.net:5333 -pubkey cj8GsiNlRkqiDElAeNMSBBMwrAl15hYPgX50+GWX/lA=

None of these server respond or use the correct version

PHP

It's probably easier to implement a time reporting function and tie it to a valid TLS certificate

https://janmg.com/time.php

<?php
  header('Content-Type:text/plain');
  header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
  header("Cache-Control: post-check=0, pre-check=0", false);
  header("Pragma: no-cache");
  echo gmdate("Y-m-d  H:i:s");
?>