diff options
Diffstat (limited to 'vendor')
| -rw-r--r-- | vendor/github.com/jinzhu/now/Guardfile | 3 | ||||
| -rw-r--r-- | vendor/github.com/jinzhu/now/README.md | 104 | ||||
| -rw-r--r-- | vendor/github.com/jinzhu/now/main.go | 103 | ||||
| -rw-r--r-- | vendor/github.com/jinzhu/now/now.go | 182 |
4 files changed, 0 insertions, 392 deletions
diff --git a/vendor/github.com/jinzhu/now/Guardfile b/vendor/github.com/jinzhu/now/Guardfile deleted file mode 100644 index 0b860b0..0000000 --- a/vendor/github.com/jinzhu/now/Guardfile +++ /dev/null @@ -1,3 +0,0 @@ -guard 'gotest' do - watch(%r{\.go$}) -end diff --git a/vendor/github.com/jinzhu/now/README.md b/vendor/github.com/jinzhu/now/README.md deleted file mode 100644 index 073c1c6..0000000 --- a/vendor/github.com/jinzhu/now/README.md +++ /dev/null @@ -1,104 +0,0 @@ -## Now - -Now is a time toolkit for golang - -#### Why the project named `Now`? - -```go -now.BeginningOfDay() -``` -`now` is quite readable, aha? - -#### But `now` is so common I can't search the project with my favorite search engine - -* Star it in github [https://github.com/jinzhu/now](https://github.com/jinzhu/now) -* Search it with [http://godoc.org](http://godoc.org) - -## Install - -``` -go get -u github.com/jinzhu/now -``` - -### Usage - -```go -import "github.com/jinzhu/now" - -time.Now() // 2013-11-18 17:51:49.123456789 Mon - -now.BeginningOfMinute() // 2013-11-18 17:51:00 Mon -now.BeginningOfHour() // 2013-11-18 17:00:00 Mon -now.BeginningOfDay() // 2013-11-18 00:00:00 Mon -now.BeginningOfWeek() // 2013-11-17 00:00:00 Sun -now.FirstDayMonday = true // Set Monday as first day, default is Sunday -now.BeginningOfWeek() // 2013-11-18 00:00:00 Mon -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.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 -now.EndOfWeek() // 2013-11-23 23:59:59.999999999 Sat -now.FirstDayMonday = true // Set Monday as first day, default is Sunday -now.EndOfWeek() // 2013-11-24 23:59:59.999999999 Sun -now.EndOfMonth() // 2013-11-30 23:59:59.999999999 Sat -now.EndOfQuarter() // 2013-12-31 23:59:59.999999999 Tue -now.EndOfYear() // 2013-12-31 23:59:59.999999999 Tue - - -// Use another time -t := time.Date(2013, 02, 18, 17, 51, 49, 123456789, time.Now().Location()) -now.New(t).EndOfMonth() // 2013-02-28 23:59:59.999999999 Thu - - -// Don't want be bothered with the First Day setting, Use Monday, Sunday -now.Monday() // 2013-11-18 00:00:00 Mon -now.Sunday() // 2013-11-24 00:00:00 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.New(t).Monday() // 2013-11-18 00:00:00 Sun (Last Monday if today is Sunday) -now.New(t).Sunday() // 2013-11-24 00:00:00 Sun (Beginning Of Today if today is Sunday) -now.New(t).EndOfSunday() // 2013-11-24 23:59:59.999999999 Sun (End of Today if today is Sunday) -``` - -#### Parse String - -```go -time.Now() // 2013-11-18 17:51:49.123456789 Mon - -// Parse(string) (time.Time, error) -t, err := now.Parse("12:20") // 2013-11-18 12:20:00, nil -t, err := now.Parse("1999-12-12 12:20") // 1999-12-12 12:20:00, nil -t, err := now.Parse("99:99") // 2013-11-18 12:20:00, Can't parse string as time: 99:99 - -// MustParse(string) time.Time -now.MustParse("2013-01-13") // 2013-01-13 00:00:00 -now.MustParse("02-17") // 2013-02-17 00:00:00 -now.MustParse("2-17") // 2013-02-17 00:00:00 -now.MustParse("8") // 2013-11-18 08:00:00 -now.MustParse("2002-10-12 22:14") // 2002-10-12 22:14:00 -now.MustParse("99:99") // panic: Can't parse string as time: 99:99 -``` - -Extend `now` to support more formats is quite easy, just update `TimeFormats` variable with `time.Format` like time layout - -```go -now.TimeFormats = append(now.TimeFormats, "02 Jan 2006 15:04") -``` - -Please send me pull requests if you want a format to be supported officially - -# Author - -**jinzhu** - -* <http://github.com/jinzhu> -* <wosmvp@gmail.com> -* <http://twitter.com/zhangjinzhu> - -## License - -Released under the [MIT License](http://www.opensource.org/licenses/MIT). diff --git a/vendor/github.com/jinzhu/now/main.go b/vendor/github.com/jinzhu/now/main.go deleted file mode 100644 index 5210ba2..0000000 --- a/vendor/github.com/jinzhu/now/main.go +++ /dev/null @@ -1,103 +0,0 @@ -// Package now is a time toolkit for golang. -// -// More details README here: https://github.com/jinzhu/now -// -// import "github.com/jinzhu/now" -// -// now.BeginningOfMinute() // 2013-11-18 17:51:00 Mon -// now.BeginningOfDay() // 2013-11-18 00:00:00 Mon -// now.EndOfDay() // 2013-11-18 23:59:59.999999999 Mon -package now - -import "time" - -var FirstDayMonday bool -var TimeFormats = []string{"1/2/2006", "1/2/2006 15:4:5", "2006-1-2 15:4:5", "2006-1-2 15:4", "2006-1-2", "1-2", "15:4:5", "15:4", "15", "15:4:5 Jan 2, 2006 MST"} - -type Now struct { - time.Time -} - -func New(t time.Time) *Now { - return &Now{t} -} - -func BeginningOfMinute() time.Time { - return New(time.Now()).BeginningOfMinute() -} - -func BeginningOfHour() time.Time { - return New(time.Now()).BeginningOfHour() -} - -func BeginningOfDay() time.Time { - return New(time.Now()).BeginningOfDay() -} - -func BeginningOfWeek() time.Time { - return New(time.Now()).BeginningOfWeek() -} - -func BeginningOfMonth() time.Time { - return New(time.Now()).BeginningOfMonth() -} - -func BeginningOfQuarter() time.Time { - return New(time.Now()).BeginningOfQuarter() -} - -func BeginningOfYear() time.Time { - return New(time.Now()).BeginningOfYear() -} - -func EndOfMinute() time.Time { - return New(time.Now()).EndOfMinute() -} - -func EndOfHour() time.Time { - return New(time.Now()).EndOfHour() -} - -func EndOfDay() time.Time { - return New(time.Now()).EndOfDay() -} - -func EndOfWeek() time.Time { - return New(time.Now()).EndOfWeek() -} - -func EndOfMonth() time.Time { - return New(time.Now()).EndOfMonth() -} - -func EndOfQuarter() time.Time { - return New(time.Now()).EndOfQuarter() -} - -func EndOfYear() time.Time { - return New(time.Now()).EndOfYear() -} - -func Monday() time.Time { - return New(time.Now()).Monday() -} - -func Sunday() time.Time { - return New(time.Now()).Sunday() -} - -func EndOfSunday() time.Time { - return New(time.Now()).EndOfSunday() -} - -func Parse(strs ...string) (time.Time, error) { - return New(time.Now()).Parse(strs...) -} - -func MustParse(strs ...string) time.Time { - return New(time.Now()).MustParse(strs...) -} - -func Between(time1, time2 string) bool { - return New(time.Now()).Between(time1, time2) -} diff --git a/vendor/github.com/jinzhu/now/now.go b/vendor/github.com/jinzhu/now/now.go deleted file mode 100644 index 97208d5..0000000 --- a/vendor/github.com/jinzhu/now/now.go +++ /dev/null @@ -1,182 +0,0 @@ -package now - -import ( - "errors" - "regexp" - "time" -) - -func (now *Now) BeginningOfMinute() time.Time { - return now.Truncate(time.Minute) -} - -func (now *Now) BeginningOfHour() time.Time { - return now.Truncate(time.Hour) -} - -func (now *Now) BeginningOfDay() time.Time { - d := time.Duration(-now.Hour()) * time.Hour - return now.BeginningOfHour().Add(d) -} - -func (now *Now) BeginningOfWeek() time.Time { - t := now.BeginningOfDay() - weekday := int(t.Weekday()) - if FirstDayMonday { - if weekday == 0 { - weekday = 7 - } - weekday = weekday - 1 - } - - d := time.Duration(-weekday) * 24 * time.Hour - return t.Add(d) -} - -func (now *Now) BeginningOfMonth() time.Time { - t := now.BeginningOfDay() - d := time.Duration(-int(t.Day())+1) * 24 * time.Hour - return t.Add(d) -} - -func (now *Now) BeginningOfQuarter() time.Time { - month := now.BeginningOfMonth() - offset := (int(month.Month()) - 1) % 3 - return month.AddDate(0, -offset, 0) -} - -func (now *Now) BeginningOfYear() time.Time { - t := now.BeginningOfDay() - d := time.Duration(-int(t.YearDay())+1) * 24 * time.Hour - return t.Truncate(time.Hour).Add(d) -} - -func (now *Now) EndOfMinute() time.Time { - return now.BeginningOfMinute().Add(time.Minute - time.Nanosecond) -} - -func (now *Now) EndOfHour() time.Time { - return now.BeginningOfHour().Add(time.Hour - time.Nanosecond) -} - -func (now *Now) EndOfDay() time.Time { - return now.BeginningOfDay().Add(24*time.Hour - time.Nanosecond) -} - -func (now *Now) EndOfWeek() time.Time { - return now.BeginningOfWeek().AddDate(0, 0, 7).Add(-time.Nanosecond) -} - -func (now *Now) EndOfMonth() time.Time { - return now.BeginningOfMonth().AddDate(0, 1, 0).Add(-time.Nanosecond) -} - -func (now *Now) EndOfQuarter() time.Time { - return now.BeginningOfQuarter().AddDate(0, 3, 0).Add(-time.Nanosecond) -} - -func (now *Now) EndOfYear() time.Time { - return now.BeginningOfYear().AddDate(1, 0, 0).Add(-time.Nanosecond) -} - -func (now *Now) Monday() time.Time { - t := now.BeginningOfDay() - weekday := int(t.Weekday()) - if weekday == 0 { - weekday = 7 - } - d := time.Duration(-weekday+1) * 24 * time.Hour - return t.Truncate(time.Hour).Add(d) -} - -func (now *Now) Sunday() time.Time { - t := now.BeginningOfDay() - weekday := int(t.Weekday()) - if weekday == 0 { - return t - } else { - d := time.Duration(7-weekday) * 24 * time.Hour - return t.Truncate(time.Hour).Add(d) - } -} - -func (now *Now) EndOfSunday() time.Time { - return now.Sunday().Add(24*time.Hour - time.Nanosecond) -} - -func parseWithFormat(str string) (t time.Time, err error) { - for _, format := range TimeFormats { - t, err = time.Parse(format, str) - if err == nil { - return - } - } - err = errors.New("Can't parse string as time: " + str) - return -} - -func (now *Now) Parse(strs ...string) (t time.Time, err error) { - var setCurrentTime bool - parseTime := []int{} - currentTime := []int{now.Second(), now.Minute(), now.Hour(), now.Day(), int(now.Month()), now.Year()} - currentLocation := now.Location() - - for _, str := range strs { - onlyTime := regexp.MustCompile(`^\s*\d+(:\d+)*\s*$`).MatchString(str) // match 15:04:05, 15 - - t, err = parseWithFormat(str) - location := t.Location() - if location.String() == "UTC" { - location = currentLocation - } - - if err == nil { - parseTime = []int{t.Second(), t.Minute(), t.Hour(), t.Day(), int(t.Month()), t.Year()} - onlyTime = onlyTime && (parseTime[3] == 1) && (parseTime[4] == 1) - - for i, v := range parseTime { - // Don't reset hour, minute, second if it is a time only string - if onlyTime && i <= 2 { - continue - } - - // Fill up missed information with current time - if v == 0 { - if setCurrentTime { - parseTime[i] = currentTime[i] - } - } else { - setCurrentTime = true - } - - // Default day and month is 1, fill up it if missing it - if onlyTime { - if i == 3 || i == 4 { - parseTime[i] = currentTime[i] - continue - } - } - } - } - - if len(parseTime) > 0 { - t = time.Date(parseTime[5], time.Month(parseTime[4]), parseTime[3], parseTime[2], parseTime[1], parseTime[0], 0, location) - currentTime = []int{t.Second(), t.Minute(), t.Hour(), t.Day(), int(t.Month()), t.Year()} - } - } - return -} - -func (now *Now) MustParse(strs ...string) (t time.Time) { - t, err := now.Parse(strs...) - if err != nil { - panic(err) - } - return t -} - -func (now *Now) Between(time1, time2 string) bool { - restime := now.MustParse(time1) - restime2 := now.MustParse(time2) - return now.After(restime) && now.Before(restime2) -} |
