Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/date.h # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / date.h` 82 lines ยท 2424 bytes Raw Blame History 1 #ifndef DATE_H 2 #define DATE_H 3 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 21 }; 22 23 struct date_mode { 24 enum date_mode_type type; 25 int local; 26 const char *strftime_fmt; 27 }; 28 29 #define DATE_MODE_INIT { \ 30 .type = DATE_NORMAL, \ 31 } 32 33 /** 34 * Convenience helper for passing a constant type, like: 35 * 36 * show_date(t, tz, DATE_MODE(NORMAL)); 37 */ 38 #define DATE_MODE(t) date_mode_from_type(DATE_##t) 39 struct date_mode date_mode_from_type(enum date_mode_type type); 40 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). 45 */ 46 const char *show_date(timestamp_t time, int timezone, struct date_mode mode); 47 48 /** 49 * Parse a date format for later use with show_date(). 50 * 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. 55 */ 56 void parse_date_format(const char *format, struct date_mode *mode); 57 58 /** 59 * Release a "struct date_mode", currently only required if 60 * parse_date_format() has parsed a "DATE_STRFTIME" format. 61 */ 62 void date_mode_release(struct date_mode *mode); 63 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 int date_overflows(timestamp_t date); 72 time_t tm_to_time_t(const struct tm *tm); 73 74 /** 75 * Convert between the "[+-]HHMM" timezone format and minutes. This format is 76 * used for example as part of commit headers and reflogs. For example, the 77 * timezone -0100 is converted to -60 minutes. 78 */ 79 int tz_to_minutes(int tz); 80 int minutes_to_tz(int minutes); 81 82 #endif