@@ -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
928929func 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.
974988func (f * File ) stylesReader () * xlsxStyleSheet {
0 commit comments