repository: avoid leaking `fsmonitor` data
[git/gitster.git] / date.h
blob5d4eaba0a90e39f8684bb5500695ba07b5ea5521
1 #ifndef DATE_H
2 #define DATE_H
4 /**
5 * The date mode type. This has DATE_NORMAL at an explicit "= 0" to
6 * accommodate a memset([...], 0, [...]) initialization when "struct
7 * date_mode" is used as an embedded struct member, as in the case of
8 * e.g. "struct pretty_print_context" and "struct rev_info".
9 */
10 enum date_mode_type {
11 DATE_NORMAL = 0,
12 DATE_HUMAN,
13 DATE_RELATIVE,
14 DATE_SHORT,
15 DATE_ISO8601,
16 DATE_ISO8601_STRICT,
17 DATE_RFC2822,
18 DATE_STRFTIME,
19 DATE_RAW,
20 DATE_UNIX
23 struct date_mode {
24 enum date_mode_type type;
25 const char *strftime_fmt;
26 int local;
29 #define DATE_MODE_INIT { \
30 .type = DATE_NORMAL, \
33 /**
34 * Convenience helper for passing a constant type, like:
36 * show_date(t, tz, DATE_MODE(NORMAL));
38 #define DATE_MODE(t) date_mode_from_type(DATE_##t)
39 struct date_mode *date_mode_from_type(enum date_mode_type type);
41 /**
42 * Format <'time', 'timezone'> into static memory according to 'mode'
43 * and return it. The mode is an initialized "struct date_mode"
44 * (usually from the DATE_MODE() macro).
46 const char *show_date(timestamp_t time, int timezone, const struct date_mode *mode);
48 /**
49 * Parse a date format for later use with show_date().
51 * When the "date_mode_type" is DATE_STRFTIME the "strftime_fmt"
52 * member of "struct date_mode" will be a malloc()'d format string to
53 * be used with strbuf_addftime(), in which case you'll need to call
54 * date_mode_release() later.
56 void parse_date_format(const char *format, struct date_mode *mode);
58 /**
59 * Release a "struct date_mode", currently only required if
60 * parse_date_format() has parsed a "DATE_STRFTIME" format.
62 void date_mode_release(struct date_mode *mode);
64 void show_date_relative(timestamp_t time, struct strbuf *timebuf);
65 int parse_date(const char *date, struct strbuf *out);
66 int parse_date_basic(const char *date, timestamp_t *timestamp, int *offset);
67 int parse_expiry_date(const char *date, timestamp_t *timestamp);
68 void datestamp(struct strbuf *out);
69 #define approxidate(s) approxidate_careful((s), NULL)
70 timestamp_t approxidate_careful(const char *, int *);
71 timestamp_t approxidate_relative(const char *date);
72 int date_overflows(timestamp_t date);
73 time_t tm_to_time_t(const struct tm *tm);
74 #endif