1 #ifndef _WIMLIB_TIMESTAMP_H
2 #define _WIMLIB_TIMESTAMP_H
8 #define intervals_per_second (1000000000ULL / 100ULL)
9 #define intervals_per_microsecond (10)
10 #define nanoseconds_per_interval (100)
11 #define days_per_year (365ULL)
12 #define seconds_per_day (3600ULL * 24ULL)
13 #define intervals_per_day (seconds_per_day * intervals_per_second)
14 #define intervals_per_year (intervals_per_day * days_per_year)
15 #define years_1601_to_1970 (1970ULL - 1601ULL)
16 #define leap_years_1601_to_1970 (years_1601_to_1970 / 4ULL - 3ULL)
17 #define intervals_1601_to_1970 (years_1601_to_1970 * intervals_per_year \
18 + leap_years_1601_to_1970 * intervals_per_day)
20 static inline u64 unix_timestamp_to_wim(time_t t)
22 return (u64)intervals_1601_to_1970 + t * intervals_per_second;
26 /* Converts a timestamp as used in the WIM file to a UNIX timestamp as used in
27 * the time() function. */
28 static inline time_t wim_timestamp_to_unix(u64 timestamp)
30 return (timestamp - intervals_1601_to_1970) / intervals_per_second;
33 static inline u64 timeval_to_wim_timestamp(const struct timeval *tv)
35 return intervals_1601_to_1970
36 + (u64)tv->tv_sec * intervals_per_second
37 + (u64)tv->tv_usec * intervals_per_microsecond;
40 static inline void wim_timestamp_to_timeval(u64 timestamp, struct timeval *tv)
42 tv->tv_sec = (timestamp - intervals_1601_to_1970) / intervals_per_second;
43 tv->tv_usec = ((timestamp - intervals_1601_to_1970) /
44 intervals_per_microsecond) % 1000000;
47 static inline u64 timespec_to_wim_timestamp(const struct timespec *ts)
49 return intervals_1601_to_1970
50 + (u64)ts->tv_sec * intervals_per_second
51 + (u64)ts->tv_nsec / nanoseconds_per_interval;
55 extern u64 get_wim_timestamp();