GPS Time

Definitions

GPS Time

  • Zero at 06/01/1980 (UTC Time)
  • written as weeks since 06/01/1980 + seconds in the current week
  • Due to the original design GPS week time is stored as 10 bit integers so can only hold 1024 weeks
  • If maximum week is reached it rolls over back to 0
  • Can also be represented as absolute gps seconds which is just the seconds passed from inception
  • Not adjusted for leap seconds
  • Expresed with a resolution of 1.5 seconds

International Atomic Time (TAI) Time

  • Time standard that is specifally for Earth’s geoid
  • Based on weighted average of 450+ atomic clocks around 80 national labs worldwide
  • It’s a continuous time scale

Coordinated Universal Time (UTC) Time

  • Based on TAI + leap seconds
  • More in accordance with the earths rotation + suns position due to leap seconds adjustment
  • UTC does not have a specific starting point in terms of seconds or a zero point
  • Due to various discrepancies that had accumulated over the inception of UTC time, it was decided to start with a 10 seconds offset from TAI time

Unix / Posix Time

  • Zero at 01/01/1970 (UTC Time)
  • No leap seconds (see FAQ for more info)

Leap seconds

  • The difference between the observed solar time vs atomic clocks
  • Solar times can change due to irregularities in the earth’s rotation
  • Can only be observed
  • Updated every 6 months by IERS (International Earth Rotation and Reference Systems Service)

Calculations

GPS Aboulte To GPS Week Seconds

week_no         = floor( gps_absolute / 60 / 60 / 24 / 7 )
seconds_in_week = gps_absolute - week_no * 60 * 60 * 24 * 7

GPS Absolute To Unix Time

# leap seconds for GPS -> Unix as of 05/07/2024 is 18 seconds
# 10 years + 2 leap year days + 5 gps days
# between 01/01/1970 ~ 06/01/1980 
leap_seconds = 18

t_between_unix_to_gps = 86400 * ((365 * 10) + 2 +  5)
t_between_unix_to_gps = 315964800 

unix_time = t_between_unix_to_gps + gps_absolute - leap_seconds

UTC Time to TAI time

# leap seconds for UTC -> TAI as of 05/07/2024 is 27 seconds
# UTC has a initial 10 seconds offset
leap_seconds = 27
inital_offset = 10

tai = utc + initial_offset + leap_seconds

FAQ

How does an atomic clock work?

  • Without going into too much detail it works by observing the frequency between two energy states of atoms.
  • 1 second is defined as 9,192,631,770 transitions between two states of caesium-133 atom.

Why is GPS week time represented in weeks + weeks in the second?

  • Essentially to compact the message since navigation message to satellites need to be as compact as possible.
  • 10 bits for week (2^10 = 1024 weeks) and 19 bits (2^19 = 524288 seconds) for seconds in a week (60 (seconds) * 60 (minutes) * 24 (hours) * 7 (days) / 1.5 (interval))
  • Smaller than 32 bits (2^32 = 4294967296 seconds | 139 years) needed for seconds.

Why are we subtracting 18 seconds from the GPS absolute to Unix time conversion when both times don’t take into account leap seconds?

  • While Unix time does not take into account leap seconds and every single day contains exactly 86,400 seconds it does deal with it by jumping back by 1 in the next day as highlighted by the bolded time in the table below.
UTC Time Unix Time GPS Time
1998-12-31T23:59:59.75 915148799.75 599184011.75
1998-12-31T23:59:60.00 915148800.00 599184012.00
1998-12-31T23:59:60.25 915148800.25 599184012.25
1998-12-31T23:59:60.50 915148800.50 599184012.50
1998-12-31T23:59:60.75 915148800.75 599184012.75
1999-01-01T00:00:00.00 915148800.00 599184013.00
1999-01-01T00:00:00.25 915148800.25 599184013.25
Written on July 8, 2024