Initial commit (current version is wimlib 0.6.2)
[wimlib] / src / timestamp.h
1 #ifndef _WIMLIB_TIMESTAMP_H
2 #define _WIMLIB_TIMESTAMP_H
3
4 #include "util.h"
5 #include <time.h>
6
7 #define intervals_per_second (1000000000ULL / 100ULL)
8 #define days_per_year (365ULL)
9 #define seconds_per_day (3600ULL * 24ULL)
10 #define intervals_per_day (seconds_per_day * intervals_per_second)
11 #define intervals_per_year (intervals_per_day * days_per_year)
12 #define years_1601_to_1970 (1970ULL - 1601ULL)
13 #define leap_years_1601_to_1970 (years_1601_to_1970 / 4ULL - 3ULL)
14 #define intervals_1601_to_1970 (years_1601_to_1970 * intervals_per_year \
15                                 + leap_years_1601_to_1970 * intervals_per_day)
16
17 /* 
18  * Returns the number of 100-nanosecond intervals that have elapsed since
19  * 12:00 A.M., January 1, 1601 UTC.
20  */
21 static inline u64 get_timestamp()
22 {
23         return (u64)intervals_1601_to_1970 + (u64)time(NULL) * intervals_per_second;
24 }
25
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 ms_timestamp_to_unix(u64 timestamp)
29 {
30         return (timestamp - intervals_1601_to_1970) / intervals_per_second;
31 }
32
33 #endif