dateutils

package
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dateutils provides functions to work with dates.

Index

Examples

Constants

View Source
const CrossrefDateTimeFormat = "20060102150405"

CrossrefDateTimeFormat is the Crossref date format with time, used in XML for content registration.

View Source
const Iso8601DateFormat = "2006-01-02"

Iso8601DateFormat is the ISO 8601 date format without time.

View Source
const Iso8601DateTimeFormat = "2006-01-02T15:04:05Z"

Iso8601DateTimeFormat is the ISO 8601 date format with time.

Variables

This section is empty.

Functions

func GetDateFromCrossrefParts added in v0.2.8

func GetDateFromCrossrefParts(strParts ...string) string

GetDateFromCrossrefParts returns a date string from Crossref XML date parts

func GetDateFromDateParts

func GetDateFromDateParts(dateAsParts [][]int) string

GetDateFromDateParts returns a date string from date parts

func GetDateFromParts

func GetDateFromParts(parts ...int) string

GetDateFromParts returns a date string from parts

func GetDateFromUnixTimestamp

func GetDateFromUnixTimestamp(timestamp int64) string

GetDateFromUnixTimestamp returns a date string from a Unix timestamp

Example
package main

import (
	"fmt"

	"github.com/front-matter/commonmeta/dateutils"
)

func main() {
	s := dateutils.GetDateFromUnixTimestamp(1611312000)
	fmt.Println(s)
}
Output:
2021-01-22

func GetDateParts added in v0.2.4

func GetDateParts(iso8601Time string) map[string][][]int

GetDateParts return date parts from an ISO 8601 date string

Example
package main

import (
	"fmt"

	"github.com/front-matter/commonmeta/dateutils"
)

func main() {
	m := dateutils.GetDateParts("2023-12-06")
	fmt.Println(m)
}
Output:
map[date-parts:[[2023 12 6]]]

func GetDateTimeFromUnixTimestamp added in v0.2.14

func GetDateTimeFromUnixTimestamp(timestamp int64) string

GetDateTimeFromUnixTimestamp returns a datetime string from a Unix timestamp

func ParseDate added in v0.2.8

func ParseDate(date string) string

ParseDate parses date strings in various formats and returns a date string in ISO 8601 format

func StripMilliseconds added in v0.2.14

func StripMilliseconds(iso8601Time string) string
Example
package main

import (
	"fmt"

	"github.com/front-matter/commonmeta/dateutils"
)

func main() {
	s := dateutils.StripMilliseconds("2021-01-22T10:00:00.000Z")
	fmt.Println(s)
}
Output:
2021-01-22T10:00:00Z

Types

type DateStruct added in v0.2.14

type DateStruct struct {
	Year  string
	Month string
	Day   string
}

func GetDateStruct added in v0.2.14

func GetDateStruct(iso8601Time string) DateStruct

GetDateStruct returns struct with date (year, month, day) from an ISO 8601 date string

Jump to

Keyboard shortcuts

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