date

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2022 License: MIT Imports: 2 Imported by: 0

README

date.Date

Tests GitHub go.mod Go version GitHub

Represents dates with values from January 1, 0001 Anno Domini (Common Era) through December 31, 9999 A.D (C.E) in Gregorian calendar. date.Date represents number of days since January 1, 001.

Installation

date.Date is compatible with modern Go releases in module mode, with Go installed:

go get github.com/tomaspavlic/date

date.Date vs time.Time

time.Time consists of wall and ext encode the wall time seconds, wall time nanoseconds, and optional monotonic clock reading in nanoseconds. time.Time also contains time.Location. The overall size of the struct is 24 bytes. Working in date.Date is reduced to just be just single int64 therefore 1/3 of time.Time size.

Usage

import "github.com/tomaspavlic/date"
// Create date.Date by just year, month and day
someDate := date.Create(2000, 1, 1)
// `date.Date` has similar functions as build-in `time.Time`
numberOfDays := date.Since(someDate)
fmt.Println("Number of days since 2000-01-01:", numberOfDays)

License

This library is distributed under the MIT license found in the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Since

func Since(d Date) int64

Since returns number of days since d.

Types

type Date

type Date int64

Represents dates with values from January 1, 0001 Anno Domini (Common Era) through December 31, 9999 A.D (C.E) in Gregorian calendar.

func Create

func Create(year int, month time.Month, day int) Date

Create creates a date containing only day number.

func FromTime

func FromTime(t time.Time) Date

FromTime converts time.Time to Date.

func Parse

func Parse(layout, value string) (Date, error)

Parse parses a formatted string and returns the date value it represents. See the documentation for the constant called Layout to see how to represent the format. The second argument must be parseable using the format string (layout) provided as the first argument.

func Today

func Today() Date

Today returns current date only.

func (Date) AddDate

func (d Date) AddDate(years int, months int, days int) Date

AddDate returns the date corresponding to adding the given number of years, months, and days to t. For example, AddDate(-1, 2, 3) applied to January 1, 2011 returns March 4, 2010.

AddDate normalizes its result in the same way that Date does, so, for example, adding one month to October 31 yields December 1, the normalized form for November 31.

func (Date) AddDays

func (d Date) AddDays(value int) Date

AddDays the specified number of days to the value of this instance.

func (Date) After

func (d Date) After(u Date) bool

After reports whether the date instant d is after u.

func (Date) Before

func (d Date) Before(u Date) bool

Before reports whether the date instant d is before u.

func (Date) Day

func (d Date) Day() int

Day returns the day of specified by d.

func (Date) Equal

func (d Date) Equal(u Date) bool

Equal reports whether d and u represent the same date instant.

func (Date) Month

func (d Date) Month() time.Month

Month returns the month of the year specified by t.

func (Date) String

func (d Date) String() string

String returns the date formatted using the format string

"2006-01-02"

func (Date) Sub

func (d Date) Sub(u Date) int

Sub returns number of days between d and u.

func (Date) ToTime

func (d Date) ToTime(hour, min, sec, nsec int, loc *time.Location) time.Time

ToTime creates time.Time from Date by adding time.

func (Date) Weekday

func (d Date) Weekday() time.Weekday

Weekday returns the day of the week specified by t.

func (Date) Year

func (d Date) Year() int

Year returns the year in which t occurs.

func (Date) YearDay

func (d Date) YearDay() int

YearDay returns the day of the year specified by t, in the range [1,365] for non-leap years, and [1,366] in leap years.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL