Skip to content

Commit

Permalink
Rename date package to datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrich Lissé committed Apr 5, 2019
1 parent f0a96d0 commit 1c1931e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
12 changes: 6 additions & 6 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/date"
"github.com/leanovate/mite-go/datetime"
"github.com/leanovate/mite-go/mite"
"github.com/spf13/cobra"
"strings"
Expand Down Expand Up @@ -32,7 +32,7 @@ var (
)

func init() {
today := date.Today()
today := datetime.Today()
defaultFrom := today.Add(0, 0, -7)
defaultDuration, err := time.ParseDuration("0m")
if err != nil {
Expand Down Expand Up @@ -78,11 +78,11 @@ var entriesListCommand = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
direction := listOrder

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

cDate, err := date.ParseLocalDate(createDate)
cDate, err := datetime.ParseLocalDate(createDate)
if err != nil {
return err
}
Expand Down Expand Up @@ -189,7 +189,7 @@ var entriesEditCommand = &cobra.Command{

// override only fields affected by set parameters of edit
if editDate != "" {
eDate, err := date.ParseLocalDate(editDate)
eDate, err := datetime.ParseLocalDate(editDate)
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/date"
"github.com/leanovate/mite-go/datetime"
"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 := date.Today()
today := datetime.Today()

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

import "time"

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

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

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

assert.Equal(t, expected, actual)
}

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

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

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

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

func TestLocalDate_Add(t *testing.T) {
expected := date.NewLocalDate(time.Date(1971, time.February, 2, 0, 0, 0, 0, time.Local))
actual := date.
expected := datetime.NewLocalDate(time.Date(1971, time.February, 2, 0, 0, 0, 0, time.Local))
actual := datetime.
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 := date.NewLocalDate(time.Date(1970, time.January, 1, 0, 0, 0, 0, time.Local)).String()
actual := datetime.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 date/minutes.go → datetime/minutes.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package date
package datetime

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

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

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

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

actual, err = date.ParseMinutes("23m11s")
actual, err = datetime.ParseMinutes("23m11s")

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

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

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

assert.Equal(t, expected, actual)
}

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

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

import (
"fmt"
"github.com/leanovate/mite-go/date"
"github.com/leanovate/mite-go/datetime"
"math"
"net/url"
"strconv"
Expand All @@ -12,7 +12,7 @@ import (
type TimeEntry struct {
Id string
Duration time.Duration
Date date.LocalDate
Date datetime.LocalDate
Note string
Billable bool
Locked bool
Expand All @@ -31,7 +31,7 @@ type TimeEntry struct {
}

type TimeEntryCommand struct {
Date *date.LocalDate
Date *datetime.LocalDate
Duration *time.Duration
Note string
UserId string
Expand All @@ -58,8 +58,8 @@ func (c *TimeEntryCommand) toRequest() *timeEntryRequest {
}

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

Expand Down Expand Up @@ -116,7 +116,7 @@ type timeEntryResponse struct {
}

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

0 comments on commit 1c1931e

Please sign in to comment.