Skip to content

Commit

Permalink
Fix AM/PM formatting (#1)
Browse files Browse the repository at this point in the history
* Fix AM/PM formatting

* Fix another issue with day of week names and updated UT
  • Loading branch information
mgolus authored and joshua committed Dec 22, 2016
1 parent 8e975ee commit 0027ab9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions strftime.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ func Strftime(t *time.Time, format string) string {
app(fmt.Sprintf("%2s", strconv.Itoa(hki)), &i, 1)
continue
case 'P':
app(t.Format("am"), &i, 1)
app(t.Format("pm"), &i, 1)
continue
case 'p':
app(t.Format("AM"), &i, 1)
app(t.Format("PM"), &i, 1)
continue
case 'M':
app(t.Format("04"), &i, 1)
Expand Down Expand Up @@ -146,7 +146,7 @@ func Strftime(t *time.Time, format string) string {
continue
case 'w', 'u': // w sunday is 0,0..6 u monday is 1,1..7
wd := int(t.Weekday() - time.Sunday)
if wd == 0 && b[i] == 'u' {
if wd == 0 && b[i+1] == 'u' {
app(strconv.Itoa(7), &i, 1)
} else {
app(strconv.Itoa(wd), &i, 1)
Expand Down Expand Up @@ -199,7 +199,7 @@ func Strftime(t *time.Time, format string) string {
strconv.Itoa(hki),
t.Format("04"),
t.Format("05"),
t.Format("AM")),
t.Format("PM")),
&i, 1)
continue
case 'R':
Expand Down
4 changes: 2 additions & 2 deletions strftime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func TestFormat(t *testing.T) {
"%k": " 9",
"%I": "09",
"%l": " 9",
"%P": "am",
"%p": "AM",
"%P": "pm",
"%p": "PM",

// Minute
"%M": "37",
Expand Down

0 comments on commit 0027ab9

Please sign in to comment.