Skip to content

Commit

Permalink
export months getter, make internal functions case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
suwhs committed Feb 13, 2016
1 parent ddf577f commit 52f093b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
18 changes: 14 additions & 4 deletions format_common.go
Expand Up @@ -3,7 +3,7 @@ package monday
import "strings"

func findInString(where string, what string, foundIndex *int, trimRight *int) (found bool) {
ind := strings.Index(where, what)
ind := strings.Index(strings.ToLower(where), strings.ToLower(what))
if ind != -1 {
*foundIndex = ind
*trimRight = len(where) - ind - len(what)
Expand Down Expand Up @@ -43,8 +43,10 @@ func commonFormatFunc(value, format string,
knw = knownPeriods
}

knw = mapToLowerCase(knw)

if knw != nil {
trimmedItem := v.item[foundIndex : len(v.item)-trimRight]
trimmedItem := strings.ToLower(v.item[foundIndex : len(v.item)-trimRight])

tr, ok := knw[trimmedItem]
if lowerCase == true {
Expand Down Expand Up @@ -103,9 +105,9 @@ func commonGenitiveFormatFunc(value, format string,
lowerCase = true
knw = knownPeriods
}

knw = mapToLowerCase(knw)
if knw != nil {
tr, _ := knw[v.item]
tr, _ := knw[strings.ToLower(v.item)]
if lowerCase == true {
tr = strings.ToLower(tr)
}
Expand Down Expand Up @@ -148,3 +150,11 @@ func createCommonParsetFuncWithGenitive(locale Locale) internalParseFunc {
knownMonthsGenitiveShortReverse[locale], knownMonthsGenitiveLongReverse[locale], knownPeriodsReverse[locale])
}
}

func mapToLowerCase(source map[string]string) map[string]string {
result := make(map[string]string)
for k, v := range source {
result[strings.ToLower(k)] = v
}
return result
}
22 changes: 22 additions & 0 deletions monday.go
Expand Up @@ -372,6 +372,17 @@ func GetShortDays(locale Locale) (arr []string) {
return
}

func GetShortMonths(locale Locale) (arr []string) {
months, ok := knownMonthsShort[locale]
if !ok {
return
}
for _, month := range months {
arr = append(arr, month)
}
return
}

func GetLongDays(locale Locale) (arr []string) {
days, ok := knownDaysLong[locale]
if !ok {
Expand All @@ -382,3 +393,14 @@ func GetLongDays(locale Locale) (arr []string) {
}
return
}

func GetLongMonths(locale Locale) (arr []string) {
months, ok := knownMonthsLong[locale]
if !ok {
return
}
for _, month := range months {
arr = append(arr, month)
}
return
}
1 change: 0 additions & 1 deletion utils_layout.go
Expand Up @@ -54,7 +54,6 @@ func extractLetterSequence(originalStr string, index int) (it dateStringLayoutIt
it.item = letters
it.isWord = isWord
it.isDigit = isDigit

return
}

Expand Down

0 comments on commit 52f093b

Please sign in to comment.