this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow unpadded days in patch headers (#14)

A closer look at the Git source shows that the rfc2822 and default
formats do not zero-pad days, so we need to accept single-digit days
when parsing. The single-digit pattern will also accept the padded
format, so there's no loss of functionality.

Change the parsing test to use single-digit values to emphasize when
padding is required and when it is not.

authored by

Billy Keyes and committed by
GitHub
f3b83ad7 4fa98017

+24 -24
+3 -3
gitdiff/patch_header.go
··· 126 126 const ( 127 127 isoFormat = "2006-01-02 15:04:05 -0700" 128 128 isoStrictFormat = "2006-01-02T15:04:05-07:00" 129 - rfc2822Format = "Mon, 02 Jan 2006 15:04:05 -0700" 129 + rfc2822Format = "Mon, 2 Jan 2006 15:04:05 -0700" 130 130 shortFormat = "2006-01-02" 131 - defaultFormat = "Mon Jan 02 15:04:05 2006 -0700" 132 - defaultLocalFormat = "Mon Jan 02 15:04:05 2006" 131 + defaultFormat = "Mon Jan 2 15:04:05 2006 -0700" 132 + defaultLocalFormat = "Mon Jan 2 15:04:05 2006" 133 133 ) 134 134 135 135 d := PatchDate{Raw: s}
+21 -21
gitdiff/patch_header_test.go
··· 65 65 } 66 66 67 67 func TestParsePatchDate(t *testing.T) { 68 - expected := time.Date(2020, 04, 11, 22, 21, 23, 0, time.UTC) 68 + expected := time.Date(2020, 4, 9, 8, 7, 6, 0, time.UTC) 69 69 70 70 tests := map[string]struct { 71 71 Input string 72 72 Output PatchDate 73 73 }{ 74 74 "default": { 75 - Input: "Sat Apr 11 15:21:23 2020 -0700", 75 + Input: "Thu Apr 9 01:07:06 2020 -0700", 76 76 Output: PatchDate{ 77 77 Parsed: expected, 78 - Raw: "Sat Apr 11 15:21:23 2020 -0700", 78 + Raw: "Thu Apr 9 01:07:06 2020 -0700", 79 79 }, 80 80 }, 81 81 "defaultLocal": { 82 - Input: "Sat Apr 11 15:21:23 2020", 82 + Input: "Thu Apr 9 01:07:06 2020", 83 83 Output: PatchDate{ 84 - Parsed: time.Date(2020, 04, 11, 15, 21, 23, 0, time.Local), 85 - Raw: "Sat Apr 11 15:21:23 2020", 84 + Parsed: time.Date(2020, 4, 9, 1, 7, 6, 0, time.Local), 85 + Raw: "Thu Apr 9 01:07:06 2020", 86 86 }, 87 87 }, 88 88 "iso": { 89 - Input: "2020-04-11 15:21:23 -0700", 89 + Input: "2020-04-09 01:07:06 -0700", 90 90 Output: PatchDate{ 91 91 Parsed: expected, 92 - Raw: "2020-04-11 15:21:23 -0700", 92 + Raw: "2020-04-09 01:07:06 -0700", 93 93 }, 94 94 }, 95 95 "isoStrict": { 96 - Input: "2020-04-11T15:21:23-07:00", 96 + Input: "2020-04-09T01:07:06-07:00", 97 97 Output: PatchDate{ 98 98 Parsed: expected, 99 - Raw: "2020-04-11T15:21:23-07:00", 99 + Raw: "2020-04-09T01:07:06-07:00", 100 100 }, 101 101 }, 102 102 "rfc": { 103 - Input: "Sat, 11 Apr 2020 15:21:23 -0700", 103 + Input: "Thu, 9 Apr 2020 01:07:06 -0700", 104 104 Output: PatchDate{ 105 105 Parsed: expected, 106 - Raw: "Sat, 11 Apr 2020 15:21:23 -0700", 106 + Raw: "Thu, 9 Apr 2020 01:07:06 -0700", 107 107 }, 108 108 }, 109 109 "short": { 110 - Input: "2020-04-11", 110 + Input: "2020-04-09", 111 111 Output: PatchDate{ 112 - Parsed: time.Date(2020, 04, 11, 0, 0, 0, 0, time.Local), 113 - Raw: "2020-04-11", 112 + Parsed: time.Date(2020, 4, 9, 0, 0, 0, 0, time.Local), 113 + Raw: "2020-04-09", 114 114 }, 115 115 }, 116 116 "raw": { 117 - Input: "1586643683 -0700", 117 + Input: "1586419626 -0700", 118 118 Output: PatchDate{ 119 119 Parsed: expected, 120 - Raw: "1586643683 -0700", 120 + Raw: "1586419626 -0700", 121 121 }, 122 122 }, 123 123 "unix": { 124 - Input: "1586643683", 124 + Input: "1586419626", 125 125 Output: PatchDate{ 126 126 Parsed: expected, 127 - Raw: "1586643683", 127 + Raw: "1586419626", 128 128 }, 129 129 }, 130 130 "unknownFormat": { 131 - Input: "4/11/2020 15:21:23 PDT", 131 + Input: "4/9/2020 01:07:06 PDT", 132 132 Output: PatchDate{ 133 - Raw: "4/11/2020 15:21:23 PDT", 133 + Raw: "4/9/2020 01:07:06 PDT", 134 134 }, 135 135 }, 136 136 "empty": {