Skip to content

Commit

Permalink
Merge branch 'master' into incorrect-diffinmonths-calculation-issue-59
Browse files Browse the repository at this point in the history
  • Loading branch information
rntdrts authored Nov 4, 2021
2 parents 4a9f35e + 1c77b65 commit 7185764
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion carbon.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (
TimeFormat = "15:04:05"
HourMinuteFormat = "15:04"
HourFormat = "15"
DayDateTimeFormat = "Mon, Aug 2, 2006 3:04 PM"
DayDateTimeFormat = "Mon, Jan 2, 2006 3:04 PM"
CookieFormat = "Monday, 02-Jan-2006 15:04:05 MST"
RFC822Format = "Mon, 02 Jan 06 15:04:05 -0700"
RFC1036Format = "Mon, 02 Jan 06 15:04:05 -0700"
Expand Down
8 changes: 7 additions & 1 deletion carbon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2596,13 +2596,19 @@ func TestCreateFromFormatInvalidFormat(t *testing.T) {
assert.NotNil(t, err)
}

func TestCreateFromTimestampUTC(t *testing.T) {
func TestCreateFromTimestampUTCDefault(t *testing.T) {
c, _ := CreateFromTimestampUTC(1171502725)

expected, _ := Create(2007, time.February, 15, 1, 25, 25, 0, "UTC")
assert.Equal(t, expected, c, "The date should be 07-02-15 01:25:25")
}

func TestCreateFromTimestampUTCByLocationParam(t *testing.T) {
c, err := CreateFromTimestamp(1624647416, "UTC")
assert.Nil(t, err)
assert.Equal(t, "Fri, Jun 25, 2021 6:56 PM", c.DayDateTimeString())
}

func TestCreateFromTimestamp(t *testing.T) {
c, _ := CreateFromTimestamp(1171502725, "Africa/Cairo")

Expand Down
12 changes: 12 additions & 0 deletions lang/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@ package lang

import (
"errors"
"go/build"
"io/ioutil"
"os"
"path/filepath"
)

// LoadLocaleText will load the translations from the locale json files according to the locale
func LoadLocaleText(l string) ([]byte, error) {
lText, err := ioutil.ReadFile("./lang/" + l + ".json")
if os.IsNotExist(err) {
gopath := os.Getenv("GOPATH")
if gopath == "" {
gopath = build.Default.GOPATH
}
lPath := filepath.Join(gopath, "src", "github.com", "uniplaces", "carbon", "lang", l + ".json")
lText, err = ioutil.ReadFile(lPath)
}

if err != nil {
return nil, errors.New("not able to read the lang file:" + err.Error())
}
Expand Down
8 changes: 8 additions & 0 deletions translator_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package carbon

import (
"strings"
"testing"
"time"

Expand All @@ -18,3 +19,10 @@ func TestTrans(t *testing.T) {
c.SetLocale("pt")
assert.Equal(t, "pt", c.GetLocale())
}

func TestLoadNonExistentResource(t *testing.T) {
tr := NewTranslator()
err := tr.loadResource("iv")
assert.NotNil(t, err)
assert.True(t, strings.Contains(err.Error(), "github.com"))
}

0 comments on commit 7185764

Please sign in to comment.