Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Issue 175 #184

Merged
merged 1 commit into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion server/i18n_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ func TestTranslationsPreInit(t *testing.T) {
p.API = api
err = p.TranslationsPreInit()
require.True(t, err.Error() == "unable to read i18n directory: readdirent: invalid argument" ||
err.Error() == "unable to read i18n directory: readdirent: not a directory")
err.Error() == "unable to read i18n directory: readdirent: not a directory" ||
err.Error() == "unable to read i18n directory: fdopendir: not a directory")

})

t.Run("no i18n files", func(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions server/occurrence.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,9 @@ func (p *Plugin) onEN(when string, user *model.User) (times []time.Time, err err
dateSplit := p.regSplit(dateUnit, "T|Z")
dateSplit = p.regSplit(dateSplit[0], "-")
timeSplit := p.regSplit(timeUnit, ":")
if len(dateSplit) < 3 || len(timeSplit) < 3 {
return []time.Time{}, errors.New("error date/time format")
}
year, _ := strconv.Atoi(dateSplit[0])
month, _ := strconv.Atoi(dateSplit[1])
day, _ := strconv.Atoi(dateSplit[2])
Expand Down Expand Up @@ -1059,6 +1062,9 @@ func (p *Plugin) everyEN(when string, user *model.User) (times []time.Time, err
dateSplit := p.regSplit(dateUnit, "T|Z")
dateSplit = p.regSplit(dateSplit[0], "-")
timeSplit := p.regSplit(timeUnit, ":")
if len(dateSplit) < 3 || len(timeSplit) < 3 {
return []time.Time{}, errors.New("error date/time format")
}
year, _ := strconv.Atoi(dateSplit[0])
month, _ := strconv.Atoi(dateSplit[1])
day, _ := strconv.Atoi(dateSplit[2])
Expand Down
99 changes: 51 additions & 48 deletions server/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,54 +603,14 @@ func (p *Plugin) normalizeDate(text string, user *model.User) (string, error) {
return "", errors.New("unrecognized date format")
}

switch parts[0] {
case T("jan"),
T("january"):
parts[0] = "01"
break
case T("feb"),
T("february"):
parts[0] = "02"
break
case T("mar"),
T("march"):
parts[0] = "03"
break
case T("apr"),
T("april"):
parts[0] = "04"
break
case T("may"):
parts[0] = "05"
break
case T("june"):
parts[0] = "06"
break
case T("july"):
parts[0] = "07"
break
case T("aug"),
T("august"):
parts[0] = "08"
break
case T("sept"),
T("september"):
parts[0] = "09"
break
case T("oct"),
T("october"):
parts[0] = "10"
break
case T("nov"),
T("november"):
parts[0] = "11"
break
case T("dec"),
T("december"):
parts[0] = "12"
break
default:
return "", errors.New("month not found")
var err error
parts[0], err = p.monthNumber(parts[0], user)
if err != nil {
return "", err
}

if len(parts) < 3 {
return "", errors.New("unrecognized date format")
}

mon, mErr := strconv.Atoi(parts[0])
Expand Down Expand Up @@ -903,6 +863,49 @@ func (p *Plugin) daySuffix(user *model.User, day string) string {
return day
}

func (p *Plugin) monthNumber(month string, user *model.User) (string, error) {

T, _ := p.translation(user)

switch month {
case T("jan"),
T("january"):
return "01", nil
case T("feb"),
T("february"):
return "02", nil
case T("mar"),
T("march"):
return "03", nil
case T("apr"),
T("april"):
return "04", nil
case T("may"):
return "05", nil
case T("june"):
return "06", nil
case T("july"):
return "07", nil
case T("aug"),
T("august"):
return "08", nil
case T("sept"),
T("september"):
return "09", nil
case T("oct"),
T("october"):
return "10", nil
case T("nov"),
T("november"):
return "11", nil
case T("dec"),
T("december"):
return "12", nil
default:
return "", errors.New("month not found")
}
}

func (p *Plugin) weekDayNumber(day string, user *model.User) int {

T, _ := p.translation(user)
Expand Down