[FR_TIME_RES_SEC] = NSEC,
[FR_TIME_RES_MIN] = (int64_t)NSEC * 60,
[FR_TIME_RES_HOUR] = (int64_t)NSEC * 3600,
- [FR_TIME_RES_DAY] = (int64_t)NSEC * 86400
+ [FR_TIME_RES_DAY] = (int64_t)NSEC * 86400,
+ [FR_TIME_RES_WEEK] = (int64_t)NSEC * 86400 * 7,
+ [FR_TIME_RES_MONTH] = FR_TIME_DUR_MONTH,
+ [FR_TIME_RES_YEAR] = FR_TIME_DUR_YEAR,
};
fr_table_num_ordered_t const fr_time_precision_table[] = {
{ L("h"), FR_TIME_RES_HOUR },
{ L("days"), FR_TIME_RES_DAY },
- { L("d"), FR_TIME_RES_DAY }
+ { L("d"), FR_TIME_RES_DAY },
+
+ { L("weeks"), FR_TIME_RES_WEEK },
+ { L("w"), FR_TIME_RES_WEEK },
/*
- * Note that there is no TIME_RES_MONTH or TIME_RES_YEAR, because months and years have variable
- * lengths.
+ * These use special values FR_TIME_DUR_MONTH and FR_TIME_DUR_YEAR
*/
+ { L("months"), FR_TIME_RES_MONTH },
+ { L("M"), FR_TIME_RES_MONTH },
+
+ { L("years"), FR_TIME_RES_YEAR },
+ { L("y"), FR_TIME_RES_YEAR },
+
};
size_t fr_time_precision_table_len = NUM_ELEMENTS(fr_time_precision_table);
*/
switch (res) {
case FR_TIME_RES_INVALID:
+ case FR_TIME_RES_YEAR:
+ case FR_TIME_RES_MONTH:
+ case FR_TIME_RES_WEEK:
case FR_TIME_RES_DAY:
case FR_TIME_RES_HOUR:
case FR_TIME_RES_MIN:
FR_TIME_RES_MIN,
FR_TIME_RES_HOUR,
FR_TIME_RES_DAY,
+ FR_TIME_RES_WEEK,
+ FR_TIME_RES_MONTH,
+ FR_TIME_RES_YEAR,
FR_TIME_RES_CSEC,
FR_TIME_RES_MSEC,
FR_TIME_RES_USEC,
#define MSEC (1000)
#define CSEC (100)
+/*
+ * Pre-defined "magic" values for time in a month and year. The number of seconds in a year is:
+ *
+ * 1 year is 365.2425 days. times 86400 seconds in a day.
+ *
+ * The average month is simply one twelfth of that. Note that the exact value for both year and month
+ * duration are really magic values, which people will never stumble upon themselves. As such, they can
+ * be used (somewhat, in some cases) as magic tokens meaning "year" or "month".
+ */
+#define FR_TIME_DUR_YEAR ((int64_t)NSEC * 31556952)
+#define FR_TIME_DUR_MONTH (FR_TIME_DUR_YEAR/12)
+
extern _Atomic int64_t our_realtime;
#ifdef HAVE_CLOCK_GETTIME