now

package module
Version: v0.0.0-...-ba8e4a9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2019 License: MIT Imports: 4 Imported by: 2

README

Now

Build Status GoDoc Language License codecov goreport

Now is time parser and toolkit for golang

Build

go get -u github.com/bingoohuang/now

Usage

import "github.com/bingoohuang/now"

now.Parse("13:39", "HH:mm").BeginningOfMinute()      // 2019-06-04 13:39:00.000 Tuesday

now.BeginningOfMinute()          // 2019-06-04 10:01:00.000 Tuesday
now.BeginningOfHour()            // 2019-06-04 10:00:00.000 Tuesday
now.BeginningOfDay()             // 2019-06-04 00:00:00.000 Tuesday
now.BeginningOfWeek(time.Monday)) // 2019-06-03 00:00:00.000 Monday
now.BeginningOfWeek(time.Sunday)) // 2019-06-02 00:00:00.000 Sunday
now.BeginningOfMonth()           // 2019-06-01 00:00:00.000 Saturday
now.BeginningOfQuarter()         // 2019-04-01 00:00:00.000 Monday
now.BeginningOfYear()            // 2019-01-01 00:00:00.000 Tuesday

now.EndOfMinute()          // 2019-06-04 10:01:59.999 Tuesday
now.EndOfHour()            // 2019-06-04 10:59:59.999 Tuesday
now.EndOfDay()             // 2019-06-04 23:59:59.999 Tuesday
now.EndOfWeek(time.Monday)) // 2019-06-09 23:59:59.999 Sunday
now.EndOfWeek(time.Sunday)) // 2019-06-08 23:59:59.999 Saturday
now.EndOfMonth()           // 2019-06-30 23:59:59.999 Sunday
now.EndOfQuarter()         // 2019-06-30 23:59:59.999 Sunday
now.EndOfYear()            // 2019-12-31 23:59:59.999 Tuesday

// Use another time
t1 := time.Date(2013, 02, 18, 17, 51, 49, 123456789, time.UTC)
now.MakeTime(t1).EndOfMonth() // 2013-02-28 23:59:59.999 Thursday
now.Monday()                  // 2019-06-03 00:00:00.000 Monday
now.Sunday()                  // 2019-06-09 00:00:00.000 Sunday
now.EndOfSunday()             // 2019-06-09 23:59:59.999 Sunday

Thanks

  1. now

Documentation

Index

Constants

View Source
const DayFmt = "yyyy-MM-dd"
View Source
const DayTimeFmt = DayFmt + " " + TimeFmt
View Source
const DayTimeMillisFmt = DayTimeFmt + ".SSS"
View Source
const Formats = "1/2/2006^" +
	"1/2/2006 15:4:5^" +
	"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"

Formats default time formats will be parsed as

View Source
const TimeFmt = "HH:mm:ss"

Variables

This section is empty.

Functions

func Between

func Between(time1, time2 string) bool

Between check now between the begin, end time or not

func ConvertLayout

func ConvertLayout(layout string) string

func FormatTime

func FormatTime(d time.Time, layout string) string

FormatTime 日期转字符串

func ParseTime

func ParseTime(d, layout string, loc *time.Location) (time.Time, error)

ParseTimeLocal 日期转字符串

func ParseTimeLocal

func ParseTimeLocal(d, layout string) (time.Time, error)

ParseTimeLocal 日期转字符串

Types

type Now

type Now struct {
	// T time
	T time.Time
	// P presentation
	P string
	// L layout
	L string
}

Now now struct

func BeginningOfDay

func BeginningOfDay() Now

BeginningOfDay beginning of day

func BeginningOfHour

func BeginningOfHour() Now

BeginningOfHour beginning of hour

func BeginningOfMinute

func BeginningOfMinute() Now

BeginningOfMinute beginning of minute

func BeginningOfMonth

func BeginningOfMonth() Now

BeginningOfMonth beginning of month

func BeginningOfQuarter

func BeginningOfQuarter() Now

BeginningOfQuarter beginning of quarter

func BeginningOfWeek

func BeginningOfWeek(weekStartDay time.Weekday) Now

BeginningOfWeek beginning of week

func BeginningOfYear

func BeginningOfYear() Now

BeginningOfYear beginning of year

func EndOfDay

func EndOfDay() Now

EndOfDay end of day

func EndOfHour

func EndOfHour() Now

EndOfHour end of hour

func EndOfMinute

func EndOfMinute() Now

EndOfMinute end of minute

func EndOfMonth

func EndOfMonth() Now

EndOfMonth end of month

func EndOfQuarter

func EndOfQuarter() Now

EndOfQuarter end of quarter

func EndOfSunday

func EndOfSunday() Now

EndOfSunday end of sunday

func EndOfWeek

func EndOfWeek(weekStartDay time.Weekday) Now

EndOfWeek end of week

func EndOfYear

func EndOfYear() Now

EndOfYear end of year

func Make

func Make(t time.Time, layout string) Now

Make initialize Now with time

func MakeNow

func MakeNow() Now

MakeNow initialize Now with now time

func MakeTime

func MakeTime(t time.Time) Now

MakeTime initialize Now with time

func Monday

func Monday() Now

Monday monday

func MustParseAny

func MustParseAny(strs string, formats ...string) Now

MustParseAny must parse string to Now or will panic

func MustParseAnyInLocation

func MustParseAnyInLocation(loc *time.Location, strs string, formats ...string) Now

MustParseAnyInLocation must parse string to Now in location or will panic

func Parse

func Parse(d, layout string) (now Now, err error)

Parse parses d in layout to now

func ParseAny

func ParseAny(strs string, formats ...string) (Now, error)

ParseAny parse string to Now

func ParseAnyInLocation

func ParseAnyInLocation(loc *time.Location, strs string, formats ...string) (Now, error)

ParseAnyInLocation parse string to Now in location

func Sunday

func Sunday() Now

Sunday sunday

func (Now) BeginningOfDay

func (n Now) BeginningOfDay() Now

BeginningOfDay beginning of day

func (Now) BeginningOfHalf

func (n Now) BeginningOfHalf() Now

BeginningOfHalf beginning of half year

func (Now) BeginningOfHour

func (n Now) BeginningOfHour() Now

BeginningOfMinute beginning of hour

func (Now) BeginningOfMinute

func (n Now) BeginningOfMinute() Now

BeginningOfMinute beginning of minute

func (Now) BeginningOfMonth

func (n Now) BeginningOfMonth() Now

BeginningOfMonth beginning of month

func (Now) BeginningOfQuarter

func (n Now) BeginningOfQuarter() Now

BeginningOfQuarter beginning of quarter

func (Now) BeginningOfWeek

func (n Now) BeginningOfWeek(weekStartDay time.Weekday) Now

BeginningOfWeek beginning of week

func (Now) BeginningOfYear

func (n Now) BeginningOfYear() Now

BeginningOfYear BeginningOfYear beginning of year

func (Now) Between

func (n Now) Between(a, b Now) bool

Between tells whether n between a and b.

func (Now) EndOfDay

func (n Now) EndOfDay() Now

EndOfDay end of day

func (Now) EndOfHalf

func (n Now) EndOfHalf() Now

EndOfHalf end of half year

func (Now) EndOfHour

func (n Now) EndOfHour() Now

EndOfHour end of hour

func (Now) EndOfMinute

func (n Now) EndOfMinute() Now

EndOfMinute end of minute

func (Now) EndOfMonth

func (n Now) EndOfMonth() Now

EndOfMonth end of month

func (Now) EndOfQuarter

func (n Now) EndOfQuarter() Now

EndOfQuarter end of quarter

func (Now) EndOfSunday

func (n Now) EndOfSunday() Now

EndOfSunday end of sunday

func (Now) EndOfWeek

func (n Now) EndOfWeek(weekStartDay time.Weekday) Now

EndOfWeek end of week

func (Now) EndOfYear

func (n Now) EndOfYear() Now

EndOfYear end of year

func (Now) Format

func (n Now) Format(layout string) string

Format formats t in layout.

func (Now) MarshalJSON

func (n Now) MarshalJSON() ([]byte, error)

MarshalJSON marshal n to JSON

func (Now) Monday

func (n Now) Monday() Now

Monday monday

func (Now) MustParseAny

func (n Now) MustParseAny(strs string, formats ...string) Now

MustParseAny must parse string to time or it will panic

func (Now) Offset

func (n Now) Offset(offset time.Duration) Now

Offset add offset to n

func (*Now) Parse

func (n *Now) Parse(d, layout string) (err error)

Parse parses d in layout to time.Time

func (*Now) ParseAny

func (n *Now) ParseAny(strs string, formats ...string) (err error)

ParseAny parse string to time

func (Now) RoundNano

func (n Now) RoundNano() Now

RoundNano add offset to n

func (Now) String

func (n Now) String() string

String returns n's presentation.

func (Now) Sunday

func (n Now) Sunday() Now

Sunday sunday

func (*Now) UnmarshalJSON

func (n *Now) UnmarshalJSON(buf []byte) error

UnmarshalJSON unmarshal JSON buf to n

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL