Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/sinlovgo/timezone

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/sinlovgo/timezone

  • v1.1.1
  • Source
  • Go
  • Socket score

Version published
Created
Source

TravisBuildStatus GoDoc GoReportCard codecov

for what

  • this project used to golang timezone

depends

in go mod project

# test version info
$ git ls-remote -q http://github.com/sinlovgo/timezone.git

# test depends see full version
$ go list -v -m -versions github.com/sinlovgo/timezone
# or use last version add go.mod by script
$ echo "go mod edit -require=$(go list -m -versions github.com/sinlovgo/timezone | awk '{print $1 "@" $NF}')"
$ echo "go mod vendor"

usage

set timezone

import "github.com/sinlovgo/timezone"
func main() {
	// use set of second time string
	timezone.Second()
	// use set of micro time string
	timezone.Micro()
	// timestamp unix
	timezone.TimestampSecond()
	// timestamp unix nano
	timezone.TimestampUnixNano()
	// UTC string
	timezone.UTCSecond()
	// UTC string as Micro
	timezone.UTCMicro()
	// use Asia/Shanghai
	timezone.SetZoneByName(timezone.ZoneAsiaShanghai)

	timezone.ZoneUTC
	timezone.ZoneGMT
	timezone.ZoneCET
	timezone.ZoneCST

	// this location
	timezone.SetZoneLocation()

	timezone.ZoneCEST
}

layout

format for golang

import "github.com/sinlovgo/timezone"
	timezone.LayoutSecond
	timezone.LayoutMicro
	timezone.LayoutISO8601TimeSecond
	timezone.LayoutISO8601TimeMicro
	timezone.LayoutISO8601TimeUTC

now

import "github.com/sinlovgo/timezone"
func main() {
	// use set of second time string
	timezone.Second()
	// use set of micro time string
	timezone.Micro()
	// timestamp unix
	timezone.TimestampSecond()
	// timestamp unix nano
	timezone.TimestampUnixNano()
	// UTC string
	timezone.UTCSecond()
	// UTC string as Micro
	timezone.UTCMicro()
	// use Asia/Shanghai
	timezone.SetZoneByName(timezone.ZoneAsiaShanghai)
	// this location
	timezone.SetZoneLocation()
}

Parse

import "github.com/sinlovgo/timezone"
func main() {
	timestamp, err := timezone.ParseTimestamp("2006-01-02 15:04:05", "2018-07-11 15:07:51")
	timestampSecond, err := timestamp.ParseTimestampSecond("2018-07-11 15:07:51")
}

timeparse

import "github.com/sinlovgo/timezone/timeparse"
func main() {
	testTime := "2020-02-25T16:52:18Z"
	parseLocation, err := Location(timezone.LayoutISO8601TimeSecond, timezone.LayoutISO8601TimeMicro,
		testTime,
		timezone.ZoneUTC, timezone.ZoneAsiaShanghai)
}

Compare

import "github.com/sinlovgo/timezone"
func main() {
	timeFrom := "2018-07-11 15:07:51"
	timeTo := "2018-07-12 15:07:51"
	compareLocationEQ, err := timestamp.CompareEQ(timeFrom, timeTo, "2006-01-02 15:04:05")
	timeFrom := "2018-07-11 15:07:51"
	timeTo := "2018-07-12 15:07:51"
	compareLocation, err := timestamp.CompareGT(timeFrom, timeTo, timestamp.LayoutSecond)
	timeFrom := "2018-07-11 15:07:51"
	timeTo := "2018-07-12 15:07:51"
	compare, err := timestamp.CompareSecondLT(timeFrom, timeTo)
}

Calc

import "github.com/sinlovgo/timezone"
func main() {
	calcDurationSecond := time.Duration(-30) * time.Minute
	calcDuration := timestamp.CalcDuration(calcDurationSecond, timestamp.LayoutMicro)

	calcDateSecond := timestamp.CalcDateSecond(2, 3, 10)
	calcDateMicro := timestamp.CalcDateMicro(2, 2, 2)

	calcDay := timestamp.CalcDay(10, LayoutSecond)
	calcDaySecond := timestamp.CalcDaySecond(1)
	calcMonthSecond := timestamp.CalcMonthSecond(-1)
	calcYearSecond := timestamp.CalcYearSecond(-1)
}

start time

import "github.com/sinlovgo/timezone"
func main() {
	yesterdaySecond := StartDaySecond(-1)
	lastMonthMicro := StartMonthMicro(-1)
	lastYearSecond := StartYearSecond(-1)
}

dev

make init
  • test code
make test

add main.go file and run

make run

dev

evn

  • golang sdk 1.13+

docker

base docker file can replace

FAQs

Package last updated on 15 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc