MCPcopy Create free account
hub / github.com/git/git / match_tz

Function match_tz

date.c:798–833  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

796}
797
798static int match_tz(const char *date, int *offp)
799{
800 char *end;
801 int hour = strtoul(date + 1, &end, 10);
802 int n = end - (date + 1);
803 int min = 0;
804
805 if (n == 4) {
806 /* hhmm */
807 min = hour % 100;
808 hour = hour / 100;
809 } else if (n != 2) {
810 min = 99; /* random crap */
811 } else if (*end == ':') {
812 /* hh:mm? */
813 min = strtoul(end + 1, &end, 10);
814 if (end - (date + 1) != 5)
815 min = 99; /* random crap */
816 } /* otherwise we parsed "hh" */
817
818 /*
819 * Don't accept any random crap. Even though some places have
820 * offset larger than 12 hours (e.g. Pacific/Kiritimati is at
821 * UTC+14), there is something wrong if hour part is much
822 * larger than that. We might also want to check that the
823 * minutes are divisible by 15 or something too. (Offset of
824 * Kathmandu, Nepal is UTC+5:45)
825 */
826 if (min < 60 && hour < 24) {
827 int offset = hour * 60 + min;
828 if (*date == '-')
829 offset = -offset;
830 *offp = offset;
831 }
832 return end - date;
833}
834
835static void date_string(timestamp_t date, int offset, struct strbuf *buf)
836{

Callers 1

parse_date_basicFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected