Add support for GPS week on datetime

(Sorry if this is not the right place to post it!)

In space and navigation, it is very common to use the GPS week and day of the week as a way to write time. It is defined as the number of weeks (starting on Sunday) since Jan 6th 1980. A calendar can be found here. Today, we are in GPS Week 2268.

Adding a new strptime/strftime code for it should be trivial enough, the most difficult part being choosing an unused letter for it. Is it possible, or is it too niche?

Thanks

Out of curiosity, what’s the standard format for GPS Week? I have used GPS in (non-professional) navigation most of my life and I’ve never seen this format before

Too niche, IMO. There’s plenty of other date-related values (for example, quarter in business use) that have just as credible an argument for inclusion, so it’s difficult to see why any one case deserves preference. The easier approach is to stick with the basically C-compatible set we have right now.

Is there a way to extend supported datetime formats? I’ve never needed anything else but this thread got me curious

I don’t think so, but I’d typically use f-strings - f"The date is {dt:%Y-%m-%d}", and for that, I’d just use a function - f"The GPS week is {gps_week(dt)}". So for me, a standalone function is perfectly fine.

1 Like

Yeah I guess converting between ISO week and GPS week should be somewhat straightforward, at least as straightforward as datetime conversions get…

datetime follows UTC semantics, GPT time does not have UTC semantics: it does not have leap seconds, thus converting from datetime time representation to GPS time is more complex that simply adjusting for an offset in the definition of the epoch. This would make the semantics of a datetime property or method to get the GPS week confusing (and IMHO not that useful).

A quick search suggets the gps_time library for converting between datetime.datetime and GPSTime (which has a GPS week number) objects: