date API: create a date.h, split from cache.h
Move the declaration of the date.c functions from cache.h, and adjust
the relevant users to include the new date.h header.
The show_ident_date() function belonged in pretty.h (it's defined in
pretty.c), its two users outside of pretty.c didn't strictly need to
include pretty.h, as they get it indirectly, but let's add it to them
anyway.
Similarly, the change to "builtin/{fast-import,show-branch,tag}.c"
isn't needed as far as the compiler is concerned, but since they all
use the "DATE_MODE()" macro we now define in date.h, let's have them
include it.
We could simply include this new header in "cache.h", but as this
change shows these functions weren't common enough to warrant
including in it in the first place. By moving them out of cache.h
changes to this API will no longer cause a (mostly) full re-build of
the project when "make" is run.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-16 08:14:02 +00:00
|
|
|
#ifndef DATE_H
|
|
|
|
#define DATE_H
|
|
|
|
|
2022-02-16 08:14:04 +00:00
|
|
|
/**
|
|
|
|
* The date mode type. This has DATE_NORMAL at an explicit "= 0" to
|
|
|
|
* accommodate a memset([...], 0, [...]) initialization when "struct
|
|
|
|
* date_mode" is used as an embedded struct member, as in the case of
|
|
|
|
* e.g. "struct pretty_print_context" and "struct rev_info".
|
|
|
|
*/
|
date API: create a date.h, split from cache.h
Move the declaration of the date.c functions from cache.h, and adjust
the relevant users to include the new date.h header.
The show_ident_date() function belonged in pretty.h (it's defined in
pretty.c), its two users outside of pretty.c didn't strictly need to
include pretty.h, as they get it indirectly, but let's add it to them
anyway.
Similarly, the change to "builtin/{fast-import,show-branch,tag}.c"
isn't needed as far as the compiler is concerned, but since they all
use the "DATE_MODE()" macro we now define in date.h, let's have them
include it.
We could simply include this new header in "cache.h", but as this
change shows these functions weren't common enough to warrant
including in it in the first place. By moving them out of cache.h
changes to this API will no longer cause a (mostly) full re-build of
the project when "make" is run.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-16 08:14:02 +00:00
|
|
|
enum date_mode_type {
|
|
|
|
DATE_NORMAL = 0,
|
|
|
|
DATE_HUMAN,
|
|
|
|
DATE_RELATIVE,
|
|
|
|
DATE_SHORT,
|
|
|
|
DATE_ISO8601,
|
|
|
|
DATE_ISO8601_STRICT,
|
|
|
|
DATE_RFC2822,
|
|
|
|
DATE_STRFTIME,
|
|
|
|
DATE_RAW,
|
|
|
|
DATE_UNIX
|
|
|
|
};
|
|
|
|
|
|
|
|
struct date_mode {
|
|
|
|
enum date_mode_type type;
|
|
|
|
const char *strftime_fmt;
|
|
|
|
int local;
|
|
|
|
};
|
|
|
|
|
2022-02-16 08:14:03 +00:00
|
|
|
#define DATE_MODE_INIT { \
|
|
|
|
.type = DATE_NORMAL, \
|
|
|
|
}
|
|
|
|
|
2022-02-16 08:14:04 +00:00
|
|
|
/**
|
date API: create a date.h, split from cache.h
Move the declaration of the date.c functions from cache.h, and adjust
the relevant users to include the new date.h header.
The show_ident_date() function belonged in pretty.h (it's defined in
pretty.c), its two users outside of pretty.c didn't strictly need to
include pretty.h, as they get it indirectly, but let's add it to them
anyway.
Similarly, the change to "builtin/{fast-import,show-branch,tag}.c"
isn't needed as far as the compiler is concerned, but since they all
use the "DATE_MODE()" macro we now define in date.h, let's have them
include it.
We could simply include this new header in "cache.h", but as this
change shows these functions weren't common enough to warrant
including in it in the first place. By moving them out of cache.h
changes to this API will no longer cause a (mostly) full re-build of
the project when "make" is run.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-16 08:14:02 +00:00
|
|
|
* Convenience helper for passing a constant type, like:
|
|
|
|
*
|
|
|
|
* show_date(t, tz, DATE_MODE(NORMAL));
|
|
|
|
*/
|
|
|
|
#define DATE_MODE(t) date_mode_from_type(DATE_##t)
|
|
|
|
struct date_mode *date_mode_from_type(enum date_mode_type type);
|
|
|
|
|
2022-02-16 08:14:04 +00:00
|
|
|
/**
|
|
|
|
* Format <'time', 'timezone'> into static memory according to 'mode'
|
|
|
|
* and return it. The mode is an initialized "struct date_mode"
|
|
|
|
* (usually from the DATE_MODE() macro).
|
|
|
|
*/
|
date API: create a date.h, split from cache.h
Move the declaration of the date.c functions from cache.h, and adjust
the relevant users to include the new date.h header.
The show_ident_date() function belonged in pretty.h (it's defined in
pretty.c), its two users outside of pretty.c didn't strictly need to
include pretty.h, as they get it indirectly, but let's add it to them
anyway.
Similarly, the change to "builtin/{fast-import,show-branch,tag}.c"
isn't needed as far as the compiler is concerned, but since they all
use the "DATE_MODE()" macro we now define in date.h, let's have them
include it.
We could simply include this new header in "cache.h", but as this
change shows these functions weren't common enough to warrant
including in it in the first place. By moving them out of cache.h
changes to this API will no longer cause a (mostly) full re-build of
the project when "make" is run.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-16 08:14:02 +00:00
|
|
|
const char *show_date(timestamp_t time, int timezone, const struct date_mode *mode);
|
2022-02-16 08:14:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a date format for later use with show_date().
|
|
|
|
*
|
|
|
|
* When the "date_mode_type" is DATE_STRFTIME the "strftime_fmt"
|
|
|
|
* member of "struct date_mode" will be a malloc()'d format string to
|
2022-02-16 08:14:05 +00:00
|
|
|
* be used with strbuf_addftime(), in which case you'll need to call
|
|
|
|
* date_mode_release() later.
|
2022-02-16 08:14:04 +00:00
|
|
|
*/
|
|
|
|
void parse_date_format(const char *format, struct date_mode *mode);
|
|
|
|
|
2022-02-16 08:14:05 +00:00
|
|
|
/**
|
|
|
|
* Release a "struct date_mode", currently only required if
|
|
|
|
* parse_date_format() has parsed a "DATE_STRFTIME" format.
|
|
|
|
*/
|
|
|
|
void date_mode_release(struct date_mode *mode);
|
|
|
|
|
date API: create a date.h, split from cache.h
Move the declaration of the date.c functions from cache.h, and adjust
the relevant users to include the new date.h header.
The show_ident_date() function belonged in pretty.h (it's defined in
pretty.c), its two users outside of pretty.c didn't strictly need to
include pretty.h, as they get it indirectly, but let's add it to them
anyway.
Similarly, the change to "builtin/{fast-import,show-branch,tag}.c"
isn't needed as far as the compiler is concerned, but since they all
use the "DATE_MODE()" macro we now define in date.h, let's have them
include it.
We could simply include this new header in "cache.h", but as this
change shows these functions weren't common enough to warrant
including in it in the first place. By moving them out of cache.h
changes to this API will no longer cause a (mostly) full re-build of
the project when "make" is run.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-16 08:14:02 +00:00
|
|
|
void show_date_relative(timestamp_t time, struct strbuf *timebuf);
|
|
|
|
int parse_date(const char *date, struct strbuf *out);
|
|
|
|
int parse_date_basic(const char *date, timestamp_t *timestamp, int *offset);
|
|
|
|
int parse_expiry_date(const char *date, timestamp_t *timestamp);
|
|
|
|
void datestamp(struct strbuf *out);
|
|
|
|
#define approxidate(s) approxidate_careful((s), NULL)
|
|
|
|
timestamp_t approxidate_careful(const char *, int *);
|
|
|
|
int date_overflows(timestamp_t date);
|
|
|
|
time_t tm_to_time_t(const struct tm *tm);
|
|
|
|
#endif
|