@@ -316,6 +316,19 @@ time_t gps2time(const gps_time_t *t_gps) {
316
316
return t ;
317
317
}
318
318
319
+ double gps2decimal_years (const gps_time_t & gps_time ) {
320
+ utc_tm utc ;
321
+ make_utc_tm (& gps_time , & utc );
322
+ double days_in_year = YEAR_DAYS ;
323
+
324
+ if (is_leap_year (utc .year )) {
325
+ days_in_year = LEAP_YEAR_DAYS ;
326
+ }
327
+
328
+ return static_cast < double > (utc .year ) +
329
+ static_cast < double > (utc .year_day ) / days_in_year ;
330
+ }
331
+
319
332
/** Convert a Unix `time_t` to a `gps_time_t` GPS time structure.
320
333
* Both input and output are assumed to be in GPS Time scale so no leap second
321
334
* is applied
@@ -977,6 +990,20 @@ void gps2date_params(const gps_time_t *gps_time,
977
990
utc2date (& utc_time , year , month , day , hour , min , sec );
978
991
}
979
992
993
+ double gps_time_to_decimal_years (const gps_time_t & gps_time ) {
994
+ utc_tm utc ;
995
+ make_utc_tm (& gps_time , & utc );
996
+ double days_in_year = YEAR_DAYS ;
997
+
998
+ if (is_leap_year (utc .year )) {
999
+ days_in_year = LEAP_YEAR_DAYS ;
1000
+ }
1001
+
1002
+ return static_cast < double > (utc .year ) +
1003
+ static_cast < double > (utc .year_day ) / days_in_year ;
1004
+ }
1005
+
1006
+
980
1007
/** Return the number of days in given month */
981
1008
u8 days_in_month (u16 year , u8 month ) {
982
1009
static u8 days_in_month_lookup [13 ] = {
0 commit comments