Skip to content

Commit 1ab7a99

Browse files
authored
This fixes qax-os#1455, pre generate strings months name for number format (qax-os#1456)
- Reducing string concatenation and string conversion between rune string data types Co-authored-by: Nathan Davies <ndavies@turnitin.com>
1 parent 917e6e1 commit 1ab7a99

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

numfmt.go

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,12 @@ var (
244244
monthNamesWelsh = []string{"Ionawr", "Chwefror", "Mawrth", "Ebrill", "Mai", "Mehefin", "Gorffennaf", "Awst", "Medi", "Hydref", "Tachwedd", "Rhagfyr"}
245245
// monthNamesWolof list the month names in the Wolof.
246246
monthNamesWolof = []string{"Samwiye", "Fewriye", "Maars", "Awril", "Me", "Suwe", "Sullet", "Ut", "Septàmbar", "Oktoobar", "Noowàmbar", "Desàmbar"}
247+
// monthNamesWolofAbbr list the month name abbreviations in Wolof, this prevents string concatenation
248+
monthNamesWolofAbbr = []string{"Sam.", "Few.", "Maa", "Awr.", "Me", "Suw", "Sul.", "Ut", "Sept.", "Okt.", "Now.", "Des."}
247249
// monthNamesXhosa list the month names in the Xhosa.
248-
monthNamesXhosa = []string{"Januwari", "Febuwari", "Matshi", "Aprili", "Meyi", "Juni", "Julayi", "Agasti", "Septemba", "Oktobha", "Novemba", "Disemba"}
250+
monthNamesXhosa = []string{"uJanuwari", "uFebuwari", "uMatshi", "uAprili", "uMeyi", "uJuni", "uJulayi", "uAgasti", "uSeptemba", "uOktobha", "uNovemba", "uDisemba"}
251+
// monthNamesXhosaAbbr list the mont abbreviations in the Xhosa, this prevents string concatenation
252+
monthNamesXhosaAbbr = []string{"uJan.", "uFeb.", "uMat.", "uEpr.", "uMey.", "uJun.", "uJul.", "uAg.", "uSep.", "uOkt.", "uNov.", "uDis."}
249253
// monthNamesYi list the month names in the Yi.
250254
monthNamesYi = []string{"\ua2cd", "\ua44d", "\ua315", "\ua1d6", "\ua26c", "\ua0d8", "\ua3c3", "\ua246", "\ua22c", "\ua2b0", "\ua2b0\ua2aa", "\ua2b0\ua44b"}
251255
// monthNamesZulu list the month names in the Zulu.
@@ -594,11 +598,11 @@ func localMonthsNameWelsh(t time.Time, abbr int) string {
594598
if abbr == 3 {
595599
switch int(t.Month()) {
596600
case 2, 7:
597-
return string([]rune(monthNamesWelsh[int(t.Month())-1])[:5])
601+
return monthNamesWelsh[int(t.Month())-1][:5]
598602
case 8, 9, 11, 12:
599-
return string([]rune(monthNamesWelsh[int(t.Month())-1])[:4])
603+
return monthNamesWelsh[int(t.Month())-1][:4]
600604
default:
601-
return string([]rune(monthNamesWelsh[int(t.Month())-1])[:3])
605+
return monthNamesWelsh[int(t.Month())-1][:3]
602606
}
603607
}
604608
if abbr == 4 {
@@ -621,39 +625,21 @@ func localMonthsNameVietnamese(t time.Time, abbr int) string {
621625
// localMonthsNameWolof returns the Wolof name of the month.
622626
func localMonthsNameWolof(t time.Time, abbr int) string {
623627
if abbr == 3 {
624-
switch int(t.Month()) {
625-
case 3, 6:
626-
return string([]rune(monthNamesWolof[int(t.Month())-1])[:3])
627-
case 5, 8:
628-
return string([]rune(monthNamesWolof[int(t.Month())-1])[:2])
629-
case 9:
630-
return string([]rune(monthNamesWolof[int(t.Month())-1])[:4]) + "."
631-
case 11:
632-
return "Now."
633-
default:
634-
return string([]rune(monthNamesWolof[int(t.Month())-1])[:3]) + "."
635-
}
628+
return monthNamesWolofAbbr[int(t.Month())-1]
636629
}
637630
if abbr == 4 {
638631
return monthNamesWolof[int(t.Month())-1]
639632
}
640-
return string([]rune(monthNamesWolof[int(t.Month())-1])[:1])
633+
return monthNamesWolof[int(t.Month())-1][:1]
641634
}
642635

643636
// localMonthsNameXhosa returns the Xhosa name of the month.
644637
func localMonthsNameXhosa(t time.Time, abbr int) string {
645638
if abbr == 3 {
646-
switch int(t.Month()) {
647-
case 4:
648-
return "uEpr."
649-
case 8:
650-
return "u" + string([]rune(monthNamesXhosa[int(t.Month())-1])[:2]) + "."
651-
default:
652-
return "u" + string([]rune(monthNamesXhosa[int(t.Month())-1])[:3]) + "."
653-
}
639+
return monthNamesXhosaAbbr[int(t.Month())-1]
654640
}
655641
if abbr == 4 {
656-
return "u" + monthNamesXhosa[int(t.Month())-1]
642+
return monthNamesXhosa[int(t.Month())-1]
657643
}
658644
return "u"
659645
}

0 commit comments

Comments
 (0)