Skip to content

Commit 07a4140

Browse files
committed
- 24 hour time format supported, relate issue #163;
- godoc and go test updated
1 parent 2dc3854 commit 07a4140

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

sheetpr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (o *AutoPageBreaks) getSheetPrOption(pr *xlsxSheetPr) {
9898
*o = AutoPageBreaks(pr.PageSetUpPr.AutoPageBreaks)
9999
}
100100

101-
// SetSheetPrOptions sets sheet properties.
101+
// SetSheetPrOptions provides function to sets worksheet properties.
102102
//
103103
// Available options:
104104
// CodeName(string)
@@ -120,7 +120,7 @@ func (f *File) SetSheetPrOptions(name string, opts ...SheetPrOption) error {
120120
return nil
121121
}
122122

123-
// SetSheetPrOptions sets sheet properties.
123+
// GetSheetPrOptions provides function to gets worksheet properties.
124124
//
125125
// Available options:
126126
// CodeName(string)

sheetpr_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import (
66
"testing"
77

88
"github.com/mohae/deepcopy"
9-
10-
"github.com/360EntSecGroup-Skylar/excelize"
9+
"github.com/xuri/excelize"
1110
)
1211

1312
var _ = []excelize.SheetPrOption{

sheetview_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"testing"
66

7-
"github.com/360EntSecGroup-Skylar/excelize"
7+
"github.com/xuri/excelize"
88
)
99

1010
var _ = []excelize.SheetViewOption{

styles.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,7 @@ func formatToE(i int, v string) string {
925925
// March, or the 'd' in Tuesday) below. First we convert them to arbitrary
926926
// characters unused in Excel Date formats, and then at the end, turn them to
927927
// what they should actually be.
928+
// Based off: http://www.ozgrid.com/Excel/CustomFormats.htm
928929
func parseTime(i int, v string) string {
929930
f, err := strconv.ParseFloat(v, 64)
930931
if err != nil {
@@ -943,8 +944,6 @@ func parseTime(i int, v string) string {
943944
{"mmm", "Jan"},
944945
{"mmss", "0405"},
945946
{"ss", "05"},
946-
{"hh", "15"},
947-
{"h", "3"},
948947
{"mm:", "04:"},
949948
{":mm", ":04"},
950949
{"mm", "01"},
@@ -953,13 +952,23 @@ func parseTime(i int, v string) string {
953952
{"%%%%", "January"},
954953
{"&&&&", "Monday"},
955954
}
955+
// It is the presence of the "am/pm" indicator that determins if this is a
956+
// 12 hour or 24 hours time format, not the number of 'h' characters.
957+
if is12HourTime(format) {
958+
format = strings.Replace(format, "hh", "03", 1)
959+
format = strings.Replace(format, "h", "3", 1)
960+
} else {
961+
format = strings.Replace(format, "hh", "15", 1)
962+
format = strings.Replace(format, "h", "15", 1)
963+
}
956964
for _, repl := range replacements {
957965
format = strings.Replace(format, repl.xltime, repl.gotime, 1)
958966
}
959967
// If the hour is optional, strip it out, along with the possible dangling
960968
// colon that would remain.
961969
if val.Hour() < 1 {
962970
format = strings.Replace(format, "]:", "]", 1)
971+
format = strings.Replace(format, "[03]", "", 1)
963972
format = strings.Replace(format, "[3]", "", 1)
964973
format = strings.Replace(format, "[15]", "", 1)
965974
} else {
@@ -969,6 +978,11 @@ func parseTime(i int, v string) string {
969978
return val.Format(format)
970979
}
971980

981+
// is12HourTime checks whether an Excel time format string is a 12 hours form.
982+
func is12HourTime(format string) bool {
983+
return strings.Contains(format, "am/pm") || strings.Contains(format, "AM/PM") || strings.Contains(format, "a/p") || strings.Contains(format, "A/P")
984+
}
985+
972986
// stylesReader provides function to get the pointer to the structure after
973987
// deserialization of xl/styles.xml.
974988
func (f *File) stylesReader() *xlsxStyleSheet {

0 commit comments

Comments
 (0)