File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -401,10 +401,20 @@ pub fn (t Time) custom_format(s string) string {
401401 sb.write_string (ordinal_suffix (t.month))
402402 }
403403 'MMM' {
404- sb.write_string (long_months[t.month - 1 ][0 ..3 ])
404+ m := if t.month > = 1 && t.month < = 12 {
405+ long_months[t.month - 1 ][0 ..3 ]
406+ } else {
407+ long_months[0 ][0 ..3 ]
408+ }
409+ sb.write_string (m)
405410 }
406411 'MMMM' {
407- sb.write_string (long_months[t.month - 1 ])
412+ m := if t.month > = 1 && t.month < = 12 {
413+ long_months[t.month - 1 ]
414+ } else {
415+ long_months[0 ]
416+ }
417+ sb.write_string (m)
408418 }
409419 'D' {
410420 sb.write_string (t.day.str ())
Original file line number Diff line number Diff line change @@ -476,3 +476,9 @@ fn test_parse_weekday() {
476476 tm_s := tm.custom_format (format)
477477 assert tm_s == 'Thursday Jan 01 00:00:00 1970'
478478}
479+
480+ fn test_empty_time () {
481+ t := time.Time{}
482+ assert t.unix () == - 62169984000
483+ assert t.custom_format ('MMMM YYYY' ) == 'January 0'
484+ }
You can’t perform that action at this time.
0 commit comments