Skip to content

Commit

Permalink
Add display.location config property
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrich Lissé committed Apr 23, 2019
1 parent e9d9e32 commit d6023c2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
"fmt"
"github.com/spf13/viper"
"os"
"time"
)

type Config interface {
GetApiUrl() string
GetApiKey() string
GetActivity(activity string) Activity
GetDisplayLocation() *time.Location
Get(key string) string
Set(key string, value string)
PrintAll()
Expand Down Expand Up @@ -58,6 +60,20 @@ func (c *config) GetActivity(activity string) Activity {
}
}

func (c *config) GetDisplayLocation() *time.Location {
s := c.Get("display.location")
if s == "" {
return time.Local
}

loc, err := time.LoadLocation(s)
if err != nil {
return time.Local
}

return loc
}

func (c *config) Get(key string) string {
err := viper.ReadInConfig()
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions tests/features/config.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ Feature: config
Given an empty config file called ".mite.toml"
When I execute "-c .mite.toml config serviceId=54321"
Then "-c .mite.toml config serviceId" should return "54321"
Scenario: Write & read display location
Given an empty config file called ".mite.toml"
When I execute "-c .mite.toml config display.location=UTC"
Then "-c .mite.toml config display.location" should return "UTC"

0 comments on commit d6023c2

Please sign in to comment.