solidarity transport updates
This commit is contained in:
@@ -8,19 +8,44 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
groupsstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
"gitlab.scity.coop/maas/navitia-golang/types"
|
||||
)
|
||||
|
||||
func TimeFrom(d any) *time.Time {
|
||||
func ModuleAvailable(group groupsstorage.Group, configmodules *viper.Viper) func(string) bool {
|
||||
return func(module string) bool {
|
||||
if module == "dashboard" {
|
||||
return true
|
||||
}
|
||||
groupmodules := group.Data["modules"].(map[string]any)
|
||||
modAvailable, ok := groupmodules[module].(bool)
|
||||
if ok && modAvailable && configmodules.GetBool(fmt.Sprintf("modules.%s.enabled", module)) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func TimeFrom(d any) *time.Time {
|
||||
paris, err := time.LoadLocation("Europe/Paris")
|
||||
if date, ok := d.(time.Time); ok {
|
||||
return &date
|
||||
if err != nil {
|
||||
return &date
|
||||
}
|
||||
nd := date.In(paris)
|
||||
return &nd
|
||||
} else if date, ok := d.(string); ok {
|
||||
datetime, err := time.Parse("2006-01-02T15:04:05Z", date)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
datetime, err = time.Parse("2006-01-02", date)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("cannot parse date")
|
||||
}
|
||||
}
|
||||
return &datetime
|
||||
dt := datetime.In(paris)
|
||||
return &dt
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -78,7 +103,6 @@ func RawJSON(v any) string {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSuffix(buf.String(), "\n")
|
||||
|
||||
}
|
||||
|
||||
func UnescapeHTML(s string) template.HTML {
|
||||
@@ -127,3 +151,14 @@ func strval(v interface{}) string {
|
||||
func Divide[V int | float64](a, b V) V {
|
||||
return a / b
|
||||
}
|
||||
|
||||
func ShortDuration(d time.Duration) string {
|
||||
s := d.String()
|
||||
if strings.HasSuffix(s, "m0s") {
|
||||
s = s[:len(s)-2]
|
||||
}
|
||||
if strings.HasSuffix(s, "h0m") {
|
||||
s = s[:len(s)-2]
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user