New Upstream Snapshot - golang-github-jinzhu-now

Ready changes

Summary

Merged new upstream version: 1.1.5 (was: 1.1.1).

Resulting package

Built on 2022-12-13T20:47 (took 3m19s)

The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:

apt install -t fresh-snapshots golang-github-jinzhu-now-dev

Lintian Result

Diff

diff --git a/README.md b/README.md
index 3add6bf..e81d31d 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,9 @@
 
 Now is a time toolkit for golang
 
-[![wercker status](https://app.wercker.com/status/a350da4eae6cb28a35687ba41afb565a/s/master "wercker status")](https://app.wercker.com/project/byKey/a350da4eae6cb28a35687ba41afb565a)
+[![go report card](https://goreportcard.com/badge/github.com/jinzhu/now "go report card")](https://goreportcard.com/report/github.com/jinzhu/now)
+[![test status](https://github.com/jinzhu/now/workflows/tests/badge.svg?branch=master "test status")](https://github.com/jinzhu/now/actions)
+[![MIT license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)
 
 ## Install
 
@@ -27,9 +29,6 @@ now.BeginningOfMonth()         // 2013-11-01 00:00:00 Fri
 now.BeginningOfQuarter()       // 2013-10-01 00:00:00 Tue
 now.BeginningOfYear()          // 2013-01-01 00:00:00 Tue
 
-now.WeekStartDay = time.Monday // Set Monday as first day, default is Sunday
-now.BeginningOfWeek()          // 2013-11-18 00:00:00 Mon
-
 now.EndOfMinute()              // 2013-11-18 17:51:59.999999999 Mon
 now.EndOfHour()                // 2013-11-18 17:59:59.999999999 Mon
 now.EndOfDay()                 // 2013-11-18 23:59:59.999999999 Mon
@@ -73,13 +72,17 @@ Don't be bothered with the `WeekStartDay` setting, you can use `Monday`, `Sunday
 
 ```go
 now.Monday()              // 2013-11-18 00:00:00 Mon
+now.Monday("17:44")       // 2013-11-18 17:44:00 Mon
 now.Sunday()              // 2013-11-24 00:00:00 Sun (Next Sunday)
+now.Sunday("18:19:24")    // 2013-11-24 18:19:24 Sun (Next Sunday)
 now.EndOfSunday()         // 2013-11-24 23:59:59.999999999 Sun (End of next Sunday)
 
 t := time.Date(2013, 11, 24, 17, 51, 49, 123456789, time.Now().Location()) // 2013-11-24 17:51:49.123456789 Sun
-now.With(t).Monday()       // 2013-11-18 00:00:00 Sun (Last Monday if today is Sunday)
-now.With(t).Sunday()       // 2013-11-24 00:00:00 Sun (Beginning Of Today if today is Sunday)
-now.With(t).EndOfSunday()  // 2013-11-24 23:59:59.999999999 Sun (End of Today if today is Sunday)
+now.With(t).Monday()              // 2013-11-18 00:00:00 Mon (Last Monday if today is Sunday)
+now.With(t).Monday("17:44")       // 2013-11-18 17:44:00 Mon (Last Monday if today is Sunday)
+now.With(t).Sunday()              // 2013-11-24 00:00:00 Sun (Beginning Of Today if today is Sunday)
+now.With(t).Sunday("18:19:24")    // 2013-11-24 18:19:24 Sun (Beginning Of Today if today is Sunday)
+now.With(t).EndOfSunday()         // 2013-11-24 23:59:59.999999999 Sun (End of Today if today is Sunday)
 ```
 
 ### Parse String to Time
@@ -93,7 +96,7 @@ t, err := now.Parse("2017-10")             // 2017-10-01 00:00:00, nil
 t, err := now.Parse("2017-10-13")          // 2017-10-13 00:00:00, nil
 t, err := now.Parse("1999-12-12 12")       // 1999-12-12 12:00:00, nil
 t, err := now.Parse("1999-12-12 12:20")    // 1999-12-12 12:20:00, nil
-t, err := now.Parse("1999-12-12 12:20:21") // 1999-12-12 12:20:00, nil
+t, err := now.Parse("1999-12-12 12:20:21") // 1999-12-12 12:20:21, nil
 t, err := now.Parse("10-13")               // 2013-10-13 00:00:00, nil
 t, err := now.Parse("12:20")               // 2013-11-18 12:20:00, nil
 t, err := now.Parse("12:20:13")            // 2013-11-18 12:20:13, nil
diff --git a/debian/changelog b/debian/changelog
index 66e4649..44df3b4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+golang-github-jinzhu-now (1.1.5-1) UNRELEASED; urgency=low
+
+  * New upstream release.
+
+ -- Debian Janitor <janitor@jelmer.uk>  Tue, 13 Dec 2022 20:45:45 -0000
+
 golang-github-jinzhu-now (1.1.1-2) unstable; urgency=medium
 
   [ Debian Janitor ]
diff --git a/main.go b/main.go
index c996a8a..8f78bc7 100644
--- a/main.go
+++ b/main.go
@@ -18,9 +18,9 @@ var WeekStartDay = time.Sunday
 var TimeFormats = []string{
 	"2006", "2006-1", "2006-1-2", "2006-1-2 15", "2006-1-2 15:4", "2006-1-2 15:4:5", "1-2",
 	"15:4:5", "15:4", "15",
-	"15:4:5 Jan 2, 2006 MST", "2006-01-02 15:04:05.999999999 -0700 MST", "2006-01-02T15:04:05-07:00",
-	"2006.1.2", "2006.1.2 15:04:05", "2006.01.02", "2006.01.02 15:04:05",
-	"1/2/2006", "1/2/2006 15:4:5", "2006/01/02", "2006/01/02 15:04:05",
+	"15:4:5 Jan 2, 2006 MST", "2006-01-02 15:04:05.999999999 -0700 MST", "2006-01-02T15:04:05Z0700", "2006-01-02T15:04:05Z07",
+	"2006.1.2", "2006.1.2 15:04:05", "2006.01.02", "2006.01.02 15:04:05", "2006.01.02 15:04:05.999999999",
+	"1/2/2006", "1/2/2006 15:4:5", "2006/01/02", "20060102", "2006/01/02 15:04:05",
 	time.ANSIC, time.UnixDate, time.RubyDate, time.RFC822, time.RFC822Z, time.RFC850,
 	time.RFC1123, time.RFC1123Z, time.RFC3339, time.RFC3339Nano,
 	time.Kitchen, time.Stamp, time.StampMilli, time.StampMicro, time.StampNano,
@@ -154,13 +154,14 @@ func EndOfYear() time.Time {
 }
 
 // Monday monday
-func Monday() time.Time {
-	return With(time.Now()).Monday()
+
+func Monday(strs ...string) time.Time {
+	return With(time.Now()).Monday(strs...)
 }
 
 // Sunday sunday
-func Sunday() time.Time {
-	return With(time.Now()).Sunday()
+func Sunday(strs ...string) time.Time {
+	return With(time.Now()).Sunday(strs...)
 }
 
 // EndOfSunday end of sunday
@@ -168,6 +169,11 @@ func EndOfSunday() time.Time {
 	return With(time.Now()).EndOfSunday()
 }
 
+// Quarter returns the yearly quarter
+func Quarter() uint {
+	return With(time.Now()).Quarter()
+}
+
 // Parse parse string to time
 func Parse(strs ...string) (time.Time, error) {
 	return With(time.Now()).Parse(strs...)
diff --git a/now.go b/now.go
index 353835a..2f524cc 100644
--- a/now.go
+++ b/now.go
@@ -108,6 +108,7 @@ func (now *Now) EndOfYear() time.Time {
 }
 
 // Monday monday
+/*
 func (now *Now) Monday() time.Time {
 	t := now.BeginningOfDay()
 	weekday := int(t.Weekday())
@@ -116,15 +117,42 @@ func (now *Now) Monday() time.Time {
 	}
 	return t.AddDate(0, 0, -weekday+1)
 }
+*/
 
-// Sunday sunday
-func (now *Now) Sunday() time.Time {
-	t := now.BeginningOfDay()
-	weekday := int(t.Weekday())
+func (now *Now) Monday(strs ...string) time.Time {
+	var parseTime time.Time
+	var err error
+	if len(strs) > 0 {
+		parseTime, err = now.Parse(strs...)
+		if err != nil {
+			panic(err)
+		}
+	} else {
+		parseTime = now.BeginningOfDay()
+	}
+	weekday := int(parseTime.Weekday())
 	if weekday == 0 {
-		return t
+		weekday = 7
 	}
-	return t.AddDate(0, 0, (7 - weekday))
+	return parseTime.AddDate(0, 0, -weekday+1)
+}
+
+func (now *Now) Sunday(strs ...string) time.Time {
+	var parseTime time.Time
+	var err error
+	if len(strs) > 0 {
+		parseTime, err = now.Parse(strs...)
+		if err != nil {
+			panic(err)
+		}
+	} else {
+		parseTime = now.BeginningOfDay()
+	}
+	weekday := int(parseTime.Weekday())
+	if weekday == 0 {
+		weekday = 7
+	}
+	return parseTime.AddDate(0, 0, (7 - weekday))
 }
 
 // EndOfSunday end of sunday
@@ -132,6 +160,11 @@ func (now *Now) EndOfSunday() time.Time {
 	return New(now.Sunday()).EndOfDay()
 }
 
+// Quarter returns the yearly quarter
+func (now *Now) Quarter() uint {
+	return (uint(now.Month())-1)/3 + 1
+}
+
 func (now *Now) parseWithFormat(str string, location *time.Location) (t time.Time, err error) {
 	for _, format := range now.TimeFormats {
 		t, err = time.ParseInLocation(format, str, location)
@@ -144,17 +177,17 @@ func (now *Now) parseWithFormat(str string, location *time.Location) (t time.Tim
 	return
 }
 
-var hasTimeRegexp = regexp.MustCompile(`(\s+|^\s*)\d{1,2}((:\d{1,2})*|((:\d{1,2}){2}\.(\d{3}|\d{6}|\d{9})))\s*$`) // match 15:04:05, 15:04:05.000, 15:04:05.000000 15, 2017-01-01 15:04, etc
-var onlyTimeRegexp = regexp.MustCompile(`^\s*\d{1,2}((:\d{1,2})*|((:\d{1,2}){2}\.(\d{3}|\d{6}|\d{9})))\s*$`)      // match 15:04:05, 15, 15:04:05.000, 15:04:05.000000, etc
+var hasTimeRegexp = regexp.MustCompile(`(\s+|^\s*|T)\d{1,2}((:\d{1,2})*|((:\d{1,2}){2}\.(\d{3}|\d{6}|\d{9})))(\s*$|[Z+-])`) // match 15:04:05, 15:04:05.000, 15:04:05.000000 15, 2017-01-01 15:04, 2021-07-20T00:59:10Z, 2021-07-20T00:59:10+08:00, 2021-07-20T00:00:10-07:00 etc
+var onlyTimeRegexp = regexp.MustCompile(`^\s*\d{1,2}((:\d{1,2})*|((:\d{1,2}){2}\.(\d{3}|\d{6}|\d{9})))\s*$`)            // match 15:04:05, 15, 15:04:05.000, 15:04:05.000000, etc
 
 // Parse parse string to time
 func (now *Now) Parse(strs ...string) (t time.Time, err error) {
 	var (
 		setCurrentTime  bool
 		parseTime       []int
-		currentTime     = []int{now.Nanosecond(), now.Second(), now.Minute(), now.Hour(), now.Day(), int(now.Month()), now.Year()}
 		currentLocation = now.Location()
 		onlyTimeInStr   = true
+		currentTime     = formatTimeToList(now.Time)
 	)
 
 	for _, str := range strs {
@@ -162,8 +195,7 @@ func (now *Now) Parse(strs ...string) (t time.Time, err error) {
 		onlyTimeInStr = hasTimeInStr && onlyTimeInStr && onlyTimeRegexp.MatchString(str)
 		if t, err = now.parseWithFormat(str, currentLocation); err == nil {
 			location := t.Location()
-
-			parseTime = []int{t.Nanosecond(), t.Second(), t.Minute(), t.Hour(), t.Day(), int(t.Month()), t.Year()}
+			parseTime = formatTimeToList(t)
 
 			for i, v := range parseTime {
 				// Don't reset hour, minute, second if current time str including time
@@ -190,7 +222,7 @@ func (now *Now) Parse(strs ...string) (t time.Time, err error) {
 			}
 
 			t = time.Date(parseTime[6], time.Month(parseTime[5]), parseTime[4], parseTime[3], parseTime[2], parseTime[1], parseTime[0], location)
-			currentTime = []int{t.Nanosecond(), t.Second(), t.Minute(), t.Hour(), t.Day(), int(t.Month()), t.Year()}
+			currentTime = formatTimeToList(t)
 		}
 	}
 	return
diff --git a/now_test.go b/now_test.go
index c8bab3a..23a4c1e 100644
--- a/now_test.go
+++ b/now_test.go
@@ -213,8 +213,16 @@ func TestMondayAndSunday(t *testing.T) {
 
 	assert(With(nDst).Monday(), "2017-10-23 00:00:00", "Monday DST")
 
+	assert(With(n).Monday("17:51:49"), "2013-11-18 17:51:49", "Monday")
+
+	assert(With(n).Monday("17:51"), "2013-11-18 17:51:00", "Monday")
+
 	assert(With(n).Sunday(), "2013-11-24 00:00:00", "Sunday")
 
+	assert(With(n).Sunday("18:19:20"), "2013-11-24 18:19:20", "Sunday")
+
+	assert(With(n).Sunday("18:19"), "2013-11-24 18:19:00", "Sunday")
+
 	assert(With(n2).Sunday(), "2013-11-24 00:00:00", "Sunday")
 
 	assert(With(timeCaracas).Sunday(), "2016-01-03 00:00:00", "Sunday Caracas")
@@ -276,6 +284,43 @@ func TestParse(t *testing.T) {
 
 	assert(With(n).MustParse("2011-01-01", "18"), "2011-01-01 18:00:00", "Parse two strings 2011-01-01, 18")
 
+	assert(With(n).MustParse("2002-10-12T00:14:56Z"), "2002-10-12 00:14:56", "Parse 2002-10-12T00:14:56Z")
+	assert(With(n).MustParse("2002-10-12T00:00:56Z"), "2002-10-12 00:00:56", "Parse 2002-10-12T00:00:56Z")
+	assert(With(n).MustParse("2002-10-12T00:00:00.999Z"), "2002-10-12 00:00:00.999", "Parse 2002-10-12T00:00:00.999Z")
+	assert(With(n).MustParse("2002-10-12T00:14:56.999999Z"), "2002-10-12 00:14:56.999999", "Parse 2002-10-12T00:14:56.999999Z")
+	assert(With(n).MustParse("2002-10-12T00:00:56.999999999Z"), "2002-10-12 00:00:56.999999999", "Parse 2002-10-12T00:00:56.999999999Z")
+
+	assert(With(n).MustParse("2002-10-12T00:14:56+08:00"), "2002-10-12 00:14:56", "Parse 2002-10-12T00:14:56+08:00")
+	_, off := With(n).MustParse("2002-10-12T00:14:56+08:00").Zone()
+	if (off != 28800) {
+		t.Errorf("Parse 2002-10-12T00:14:56+08:00 shouldn't lose time zone offset")
+	}
+	assert(With(n).MustParse("2002-10-12T00:00:56-07:00"), "2002-10-12 00:00:56", "Parse 2002-10-12T00:00:56-07:00")
+	_, off2 := With(n).MustParse("2002-10-12T00:00:56-07:00").Zone()
+	if (off2 != -25200){
+		t.Errorf("Parse 2002-10-12T00:00:56-07:00 shouldn't lose time zone offset")
+	}
+	assert(With(n).MustParse("2002-10-12T00:01:12.333+0200"), "2002-10-12 00:01:12.333", "Parse 2002-10-12T00:01:12.333+0200")
+	_, off3 := With(n).MustParse("2002-10-12T00:01:12.333+0200").Zone()
+	if (off3 != 7200){
+		t.Errorf("Parse 2002-10-12T00:01:12.333+0200 shouldn't lose time zone offset")
+	}
+	assert(With(n).MustParse("2002-10-12T00:00:56.999999999+08:00"), "2002-10-12 00:00:56.999999999", "Parse 2002-10-12T00:00:56.999999999+08:00")
+	_, off4 := With(n).MustParse("2002-10-12T00:14:56.999999999+08:00").Zone()
+	if (off4 != 28800) {
+		t.Errorf("Parse 2002-10-12T00:14:56.999999999+08:00 shouldn't lose time zone offset")
+	}
+	assert(With(n).MustParse("2002-10-12T00:00:56.666666-07:00"), "2002-10-12 00:00:56.666666", "Parse 2002-10-12T00:00:56.666666-07:00")
+	_, off5 := With(n).MustParse("2002-10-12T00:00:56.666666-07:00").Zone()
+	if (off5 != -25200){
+		t.Errorf("Parse 2002-10-12T00:00:56.666666-07:00 shouldn't lose time zone offset")
+	}
+	assert(With(n).MustParse("2002-10-12T00:01:12.999999999-06"), "2002-10-12 00:01:12.999999999", "Parse 2002-10-12T00:01:12.999999999-06")
+	_, off6 := With(n).MustParse("2002-10-12T00:01:12.999999999-06").Zone()
+	if (off6 != -21600){
+		t.Errorf("Parse 2002-10-12T00:01:12.999999999-06 shouldn't lose time zone offset")
+	}
+
 	TimeFormats = append(TimeFormats, "02 Jan 15:04")
 	assert(With(n).MustParse("04 Feb 12:09"), "2013-02-04 12:09:00", "Parse 04 Feb 12:09 with specified format")
 
@@ -348,6 +393,25 @@ func TestConfig(t *testing.T) {
 	}
 }
 
+func TestQuarter(t *testing.T) {
+	type test struct {
+		givenDate       time.Time
+		expectedQuarter uint
+	}
+
+	tests := []test{
+		{time.Date(2021, 6, 18, 0, 0, 0, 0, time.UTC), 2},
+		{time.Date(2021, 7, 18, 0, 0, 0, 0, time.UTC), 3},
+	}
+
+	for _, tc := range tests {
+		got := With(tc.givenDate).Quarter()
+		if got != tc.expectedQuarter {
+			t.Fatalf("Quarter %d expected, got %d", tc.expectedQuarter, got)
+		}
+	}
+}
+
 func Example() {
 	time.Now() // 2013-11-18 17:51:49.123456789 Mon
 
@@ -377,7 +441,9 @@ func Example() {
 	t := time.Date(2013, 02, 18, 17, 51, 49, 123456789, time.UTC)
 	With(t).EndOfMonth() // 2013-02-28 23:59:59.999999999 Thu
 
-	Monday()      // 2013-11-18 00:00:00 Mon
-	Sunday()      // 2013-11-24 00:00:00 Sun
-	EndOfSunday() // 2013-11-24 23:59:59.999999999 Sun
+	Monday()        // 2013-11-18 00:00:00 Mon
+	Monday("17:44") // 2013-11-18 17:44:00 Mon
+	Sunday()        // 2013-11-24 00:00:00 Sun
+	Sunday("17:44") // 2013-11-24 17:44:00 Sun
+	EndOfSunday()   // 2013-11-24 23:59:59.999999999 Sun
 }
diff --git a/time.go b/time.go
new file mode 100644
index 0000000..52dd8b2
--- /dev/null
+++ b/time.go
@@ -0,0 +1,9 @@
+package now
+
+import "time"
+
+func formatTimeToList(t time.Time) []int {
+	hour, min, sec := t.Clock()
+	year, month, day := t.Date()
+	return []int{t.Nanosecond(), sec, min, hour, day, int(month), year}
+}
diff --git a/wercker.yml b/wercker.yml
deleted file mode 100644
index 5e6ce98..0000000
--- a/wercker.yml
+++ /dev/null
@@ -1,23 +0,0 @@
-box: golang
-
-build:
-  steps:
-    - setup-go-workspace
-
-    # Gets the dependencies
-    - script:
-        name: go get
-        code: |
-          go get
-
-    # Build the project
-    - script:
-        name: go build
-        code: |
-          go build ./...
-
-    # Test the project
-    - script:
-        name: go test
-        code: |
-          go test ./...

Debdiff

[The following lists of changes regard files as different if they have different names, permissions or owners.]

Files in second set of .debs but not in first

-rw-r--r--  root/root   /usr/share/gocode/src/github.com/jinzhu/now/time.go

No differences were encountered in the control files

More details

Full run details