Skip to content

Commit

Permalink
Introduce domain package
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrich Lissé committed Apr 8, 2019
1 parent 203f7cf commit 2f6a05c
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 44 deletions.
18 changes: 9 additions & 9 deletions cmd/entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"
"github.com/cheynewallace/tabby"
"github.com/leanovate/mite-go/datetime"
"github.com/leanovate/mite-go/domain"
"github.com/leanovate/mite-go/mite"
"github.com/spf13/cobra"
"strings"
Expand All @@ -31,9 +31,9 @@ var (
)

func init() {
today := datetime.Today()
today := domain.Today()
defaultFrom := today.Add(0, 0, -7)
defaultMinutes := datetime.NewMinutes(0).String()
defaultMinutes := domain.NewMinutes(0).String()

// list
entriesListCommand.Flags().StringVarP(&listTo, "to", "t", today.String(), "list only entries until date (in YYYY-MM-DD format)")
Expand Down Expand Up @@ -75,11 +75,11 @@ var entriesListCommand = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
direction := listOrder

to, err := datetime.ParseLocalDate(listTo)
to, err := domain.ParseLocalDate(listTo)
if err != nil {
return err
}
from, err := datetime.ParseLocalDate(listFrom)
from, err := domain.ParseLocalDate(listFrom)
if err != nil {
return err
}
Expand Down Expand Up @@ -121,11 +121,11 @@ var entriesCreateCommand = &cobra.Command{
return errors.New("please set both the project AND service id (either via arguments or config)")
}

cDate, err := datetime.ParseLocalDate(createDate)
cDate, err := domain.ParseLocalDate(createDate)
if err != nil {
return err
}
cMinutes, err := datetime.ParseMinutes(createMinutes)
cMinutes, err := domain.ParseMinutes(createMinutes)
if err != nil {
return err
}
Expand Down Expand Up @@ -190,15 +190,15 @@ var entriesEditCommand = &cobra.Command{

// override only fields affected by set parameters of edit
if editDate != "" {
eDate, err := datetime.ParseLocalDate(editDate)
eDate, err := domain.ParseLocalDate(editDate)
if err != nil {
return err
}
timeEntry.Date = &eDate
}

if editMinutes != "" {
eMinutes, err := datetime.ParseMinutes(editMinutes)
eMinutes, err := domain.ParseMinutes(editMinutes)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"errors"
"github.com/cheynewallace/tabby"
"github.com/leanovate/mite-go/datetime"
"github.com/leanovate/mite-go/domain"
"github.com/leanovate/mite-go/mite"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -102,7 +102,7 @@ var trackerStopCommand = &cobra.Command{
}

func fetchLatestTimeEntryForToday() (string, error) {
today := datetime.Today()
today := domain.Today()

entries, err := deps.miteApi.TimeEntries(&mite.TimeEntryQuery{
To: &today,
Expand Down
2 changes: 1 addition & 1 deletion datetime/local_date.go → domain/local_date.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package datetime
package domain

import "time"

Expand Down
18 changes: 9 additions & 9 deletions datetime/local_date_test.go → domain/local_date_test.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
package datetime_test
package domain_test

import (
"github.com/leanovate/mite-go/datetime"
"github.com/leanovate/mite-go/domain"
"github.com/stretchr/testify/assert"
"testing"
"time"
)

func TestToday(t *testing.T) {
expected := time.Now().Local().Format("2006-01-02")
actual := datetime.Today().String()
actual := domain.Today().String()

assert.Equal(t, expected, actual)
}

func TestParseLocalDate(t *testing.T) {
expected := datetime.NewLocalDate(time.Date(1970, time.January, 1, 0, 0, 0, 0, time.Local))
actual, err := datetime.ParseLocalDate("1970-01-01")
expected := domain.NewLocalDate(time.Date(1970, time.January, 1, 0, 0, 0, 0, time.Local))
actual, err := domain.ParseLocalDate("1970-01-01")

assert.Nil(t, err)
assert.Equal(t, expected, actual)

_, err = datetime.ParseLocalDate("1970-01-01T00:00:00Z")
_, err = domain.ParseLocalDate("1970-01-01T00:00:00Z")

assert.IsType(t, &time.ParseError{}, err)
}

func TestLocalDate_Add(t *testing.T) {
expected := datetime.NewLocalDate(time.Date(1971, time.February, 2, 0, 0, 0, 0, time.Local))
actual := datetime.
expected := domain.NewLocalDate(time.Date(1971, time.February, 2, 0, 0, 0, 0, time.Local))
actual := domain.
NewLocalDate(time.Date(1970, time.January, 1, 0, 0, 0, 0, time.Local)).
Add(1, 1, 1)

Expand All @@ -37,7 +37,7 @@ func TestLocalDate_Add(t *testing.T) {

func TestLocalDate_String(t *testing.T) {
expected := "1970-01-01"
actual := datetime.NewLocalDate(time.Date(1970, time.January, 1, 0, 0, 0, 0, time.Local)).String()
actual := domain.NewLocalDate(time.Date(1970, time.January, 1, 0, 0, 0, 0, time.Local)).String()

assert.Equal(t, expected, actual)
}
2 changes: 1 addition & 1 deletion datetime/minutes.go → domain/minutes.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package datetime
package domain

import (
"math"
Expand Down
16 changes: 8 additions & 8 deletions datetime/minutes_test.go → domain/minutes_test.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
package datetime_test
package domain_test

import (
"github.com/leanovate/mite-go/datetime"
"github.com/leanovate/mite-go/domain"
"github.com/stretchr/testify/assert"
"testing"
)

func Test_ParseMinutes(t *testing.T) {
expected := datetime.NewMinutes(23)
actual, err := datetime.ParseMinutes("23m")
expected := domain.NewMinutes(23)
actual, err := domain.ParseMinutes("23m")

assert.Nil(t, err)
assert.Equal(t, expected, actual)

actual, err = datetime.ParseMinutes("22m33s")
actual, err = domain.ParseMinutes("22m33s")

assert.Nil(t, err)
assert.Equal(t, expected, actual)

_, err = datetime.ParseMinutes("1970-01-01")
_, err = domain.ParseMinutes("1970-01-01")
assert.NotNil(t, err)
}

func TestMinutes_Value(t *testing.T) {
expected := 23
actual := datetime.NewMinutes(23).Value()
actual := domain.NewMinutes(23).Value()

assert.Equal(t, expected, actual)
}

func TestMinutes_String(t *testing.T) {
expected := "23m"
actual := datetime.NewMinutes(23).String()
actual := domain.NewMinutes(23).String()

assert.Equal(t, expected, actual)
}
18 changes: 9 additions & 9 deletions mite/time_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package mite

import (
"fmt"
"github.com/leanovate/mite-go/datetime"
"github.com/leanovate/mite-go/domain"
"net/url"
"strconv"
"time"
)

type TimeEntry struct {
Id string
Minutes datetime.Minutes
Date datetime.LocalDate
Minutes domain.Minutes
Date domain.LocalDate
Note string
Billable bool
Locked bool
Expand All @@ -30,8 +30,8 @@ type TimeEntry struct {
}

type TimeEntryCommand struct {
Date *datetime.LocalDate
Minutes *datetime.Minutes
Date *domain.LocalDate
Minutes *domain.Minutes
Note string
UserId string
ProjectId string
Expand All @@ -57,8 +57,8 @@ func (c *TimeEntryCommand) toRequest() *timeEntryRequest {
}

type TimeEntryQuery struct {
From *datetime.LocalDate
To *datetime.LocalDate
From *domain.LocalDate
To *domain.LocalDate
Direction string
}

Expand Down Expand Up @@ -115,14 +115,14 @@ type timeEntryResponse struct {
}

func (r *timeEntryResponse) toTimeEntry() *TimeEntry {
d, err := datetime.ParseLocalDate(r.TimeEntry.Date)
d, err := domain.ParseLocalDate(r.TimeEntry.Date)
if err != nil {
panic(err)
}

return &TimeEntry{
Id: strconv.Itoa(r.TimeEntry.Id),
Minutes: datetime.NewMinutes(r.TimeEntry.Minutes),
Minutes: domain.NewMinutes(r.TimeEntry.Minutes),
Date: d,
Note: r.TimeEntry.Note,
Billable: r.TimeEntry.Billable,
Expand Down
10 changes: 5 additions & 5 deletions mite/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package mite

import (
"fmt"
"github.com/leanovate/mite-go/datetime"
"github.com/leanovate/mite-go/domain"
"strconv"
"time"
)

type TrackingTimeEntry struct {
Id string
Minutes datetime.Minutes
Minutes domain.Minutes
Since time.Time
}

type StoppedTimeEntry struct {
Id string
Minutes datetime.Minutes
Minutes domain.Minutes
}

type trackerResponse struct {
Expand All @@ -39,7 +39,7 @@ func (r *trackerResponse) toTrackingTimeEntry() *TrackingTimeEntry {

return &TrackingTimeEntry{
Id: strconv.Itoa(r.Tracker.TrackingTimeEntry.Id),
Minutes: datetime.NewMinutes(r.Tracker.TrackingTimeEntry.Minutes),
Minutes: domain.NewMinutes(r.Tracker.TrackingTimeEntry.Minutes),
Since: r.Tracker.TrackingTimeEntry.Since,
}
}
Expand All @@ -51,7 +51,7 @@ func (r *trackerResponse) toStoppedTimeEntry() *StoppedTimeEntry {

return &StoppedTimeEntry{
Id: strconv.Itoa(r.Tracker.StoppedTimeEntry.Id),
Minutes: datetime.NewMinutes(r.Tracker.StoppedTimeEntry.Minutes),
Minutes: domain.NewMinutes(r.Tracker.StoppedTimeEntry.Minutes),
}
}

Expand Down

0 comments on commit 2f6a05c

Please sign in to comment.