stime

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 27, 2025 License: MIT Imports: 5 Imported by: 0

README

STIME

Go Reference

Package stime provides some simplified (no time zone) time processing functions.

Feature

  • Conveniently convert to and from time.Time.
  • The underlying data is of readable integer type.
  • Serializing to JSON format is compatible with HTML5.

Dependencies

  • go 1.20+

Usage

import "gitee.com/erdian718/stime"

func main() {
	date := stime.NowDate()
	time := stime.NowTime()
	datetime := stime.NowDateTime()

	// ...
}

Note

  • No time zone.

Documentation

Overview

Package stime provides some simplified (no time zone) time processing functions.

Example
package main

import (
	"fmt"

	"gitee.com/erdian718/stime"
)

func main() {
	date := stime.NowDate()
	time := stime.NowTime()
	datetime := stime.NowDateTime()

	fmt.Println(date)
	fmt.Println(time)
	fmt.Println(datetime)
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Date

type Date uint32

Date represents a date.

func NewDate

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

NewDate creates a new date.

func NowDate

func NowDate() Date

NowDate returns the current date.

func ParseDate

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

ParseDate parses a formatted string and returns the date it represents.

func ToDate

func ToDate(t time.Time) Date

ToDate converts t to date.

func (Date) Add

func (d Date) Add(dur time.Duration) Date

Add returns the date d+dur.

func (Date) AddWith

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

AddWith returns the date corresponding to adding the given number of years, months, and days to d.

func (Date) Day

func (d Date) Day() int

Day returns the day in which d occurs.

func (Date) Format

func (d Date) Format(layout string) string

Format returns a textual representation of the date formatted according to the layout defined by the argument.

func (Date) Local

func (d Date) Local() time.Time

Local returns the local time.

func (Date) MarshalBinary

func (d Date) MarshalBinary() (data []byte, err error)

MarshalBinary encodes the receiver into a binary form and returns the result.

func (Date) MarshalText

func (d Date) MarshalText() (text []byte, err error)

MarshalText encodes the receiver into UTF-8-encoded text and returns the result.

func (Date) Month

func (d Date) Month() time.Month

Month returns the month in which d occurs.

func (Date) String

func (d Date) String() string

String returns the string of the date.

func (Date) Sub

func (d Date) Sub(other Date) time.Duration

Sub returns the duration d-other.

func (Date) UTC

func (d Date) UTC() time.Time

UTC returns the UTC time.

func (*Date) UnmarshalBinary

func (d *Date) UnmarshalBinary(data []byte) error

UnmarshalBinary must be able to decode the form generated by MarshalBinary.

func (*Date) UnmarshalText

func (d *Date) UnmarshalText(text []byte) error

UnmarshalText must be able to decode the form generated by MarshalText.

func (Date) Year

func (d Date) Year() int

Year returns the year in which d occurs.

type DateTime

type DateTime uint64

DateTime represents a datetime.

func NewDateTime

func NewDateTime(year int, month time.Month, day int, hour int, minute int, second int) DateTime

NewDateTime creates a new datetime.

func NowDateTime

func NowDateTime() DateTime

NowDateTime returns the current datetime.

func ParseDateTime

func ParseDateTime(layout string, value string) (DateTime, error)

ParseDateTime parses a formatted string and returns the datetime it represents.

func ToDateTime

func ToDateTime(t time.Time) DateTime

ToDateTime converts t to datetime.

func (DateTime) Add

func (dt DateTime) Add(dur time.Duration) DateTime

Add returns the datetime dt+dur.

func (DateTime) AddWith

func (dt DateTime) AddWith(years int, months int, days int, hours int, minutes int, seconds int) DateTime

AddWith returns the datetime corresponding to adding the given number of years, months, days, hours, minutes and seconds to dt.

func (DateTime) Day

func (dt DateTime) Day() int

Day returns the day in which dt occurs.

func (DateTime) Format

func (dt DateTime) Format(layout string) string

Format returns a textual representation of the datetime formatted according to the layout defined by the argument.

func (DateTime) Hour

func (dt DateTime) Hour() int

Hour returns the hour in which dt occurs.

func (DateTime) Local

func (dt DateTime) Local() time.Time

Local returns the local time.

func (DateTime) MarshalBinary

func (dt DateTime) MarshalBinary() (data []byte, err error)

MarshalBinary encodes the receiver into a binary form and returns the result.

func (DateTime) MarshalText

func (dt DateTime) MarshalText() (text []byte, err error)

MarshalText encodes the receiver into UTF-8-encoded text and returns the result.

func (DateTime) Minute

func (dt DateTime) Minute() int

Minute returns the minute in which dt occurs.

func (DateTime) Month

func (dt DateTime) Month() time.Month

Month returns the month in which dt occurs.

func (DateTime) Second

func (dt DateTime) Second() int

Second returns the second in which dt occurs.

func (DateTime) String

func (dt DateTime) String() string

String returns the string of the datetime.

func (DateTime) Sub

func (dt DateTime) Sub(other DateTime) time.Duration

Sub returns the duration dt-other.

func (DateTime) UTC

func (dt DateTime) UTC() time.Time

UTC returns the UTC time.

func (*DateTime) UnmarshalBinary

func (dt *DateTime) UnmarshalBinary(data []byte) error

UnmarshalBinary must be able to decode the form generated by MarshalBinary.

func (*DateTime) UnmarshalText

func (dt *DateTime) UnmarshalText(text []byte) error

UnmarshalText must be able to decode the form generated by MarshalText.

func (DateTime) Year

func (dt DateTime) Year() int

Year returns the year in which dt occurs.

type Time

type Time uint32

Time represents a time.

func NewTime

func NewTime(hour int, minute int, second int) Time

NewTime creates a new time.

func NowTime

func NowTime() Time

NowTime returns the current time.

func ParseTime

func ParseTime(layout string, value string) (Time, error)

ParseTime parses a formatted string and returns the time it represents.

func ToTime

func ToTime(t time.Time) Time

ToTime converts t to time.

func (Time) Add

func (t Time) Add(dur time.Duration) Time

Add returns the time t+dur.

func (Time) AddWith

func (t Time) AddWith(hours int, minutes int, seconds int) Time

AddWith returns the time corresponding to adding the given number of hours, minutes, and seconds to t.

func (Time) Format

func (t Time) Format(layout string) string

Format returns a textual representation of the time formatted according to the layout defined by the argument.

func (Time) Hour

func (t Time) Hour() int

Hour returns the hour in which t occurs.

func (Time) Local

func (t Time) Local() time.Time

Local returns the local time.

func (Time) MarshalBinary

func (t Time) MarshalBinary() (data []byte, err error)

MarshalBinary encodes the receiver into a binary form and returns the result.

func (Time) MarshalText

func (t Time) MarshalText() (text []byte, err error)

MarshalText encodes the receiver into UTF-8-encoded text and returns the result.

func (Time) Minute

func (t Time) Minute() int

Minute returns the minute in which t occurs.

func (Time) Second

func (t Time) Second() int

Second returns the second in which t occurs.

func (Time) String

func (t Time) String() string

String returns the string of the time.

func (Time) Sub

func (t Time) Sub(other Time) time.Duration

Sub returns the duration t-other.

func (Time) UTC

func (t Time) UTC() time.Time

UTC returns the UTC time.

func (*Time) UnmarshalBinary

func (t *Time) UnmarshalBinary(data []byte) error

UnmarshalBinary must be able to decode the form generated by MarshalBinary.

func (*Time) UnmarshalText

func (t *Time) UnmarshalText(text []byte) error

UnmarshalText must be able to decode the form generated by MarshalText.

Jump to

Keyboard shortcuts

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