diff --git a/commonxl/fmt_test.go b/commonxl/fmt_test.go index 074b8a2..36cc9a5 100644 --- a/commonxl/fmt_test.go +++ b/commonxl/fmt_test.go @@ -139,3 +139,18 @@ func TestBoolFormats(t *testing.T) { t.Fatal(`-99.0 should be "yes"`) } } + +func TestTimeFormats(t *testing.T) { + formatter := Formatter{} + formatter.Add(165, "hh:mm") + + testTime := time.Date(2014, 3, 27, 9, 37, 0, 0, time.UTC) + val, ok := formatter.Apply(165, testTime) + if ok != true { + t.Fatal("Could not format time") + } + + if val != "09:37" { + t.Fatal("Time should be 09:37, but was", val) + } +} diff --git a/commonxl/formats.go b/commonxl/formats.go index 49b58a9..ffca5bb 100644 --- a/commonxl/formats.go +++ b/commonxl/formats.go @@ -64,7 +64,7 @@ func (x *Formatter) getCellType(fmtID uint16) (CellType, bool) { } var ( - minsMatch = regexp.MustCompile("h.*m.*s") + minsMatch = regexp.MustCompile("h.*m.*s*") nonEsc = regexp.MustCompile(`([^"]|^)"`) squash = regexp.MustCompile(`[*_].`) fixEsc = regexp.MustCompile(`\\(.)`)