datemaki

package module
v0.0.0-...-9598607 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 License: Apache-2.0 Imports: 7 Imported by: 6

README

datemaki -- flexible and fancy datetime parse library

wercker status

datemaki

Specs

https://gist.github.com/shibukawa/6221750ca958a8880e01

License

Apache License, Version 2.0. See LICENSE file for details.

Documentation

Overview

Package datemaki is a flexible and fancy datetime parsing library.

This is work in progress. This package aims to handle datetime expressed in more natural languages and convert them into time.Time instances.

Currently this package supports following datetime expression, mainly used in Git commands.

* Past datetime described in ago

  • 2 seconds ago
  • 3 minutes ago
  • 4 hours ago
  • 5 days ago
  • 1 week ago
  • 2 months ago
  • 1 year, 3 months ago
  • 1.year.4.months.ago
  • 2.years.ago

* Relative date

  • now
  • today
  • yesterday
  • last friday

* Relative date and fixed time

  • noon yesterday
  • tea yesterday
  • midnight today
  • 3pm today
  • 2am last friday
  • 19:00 yesterday (under implementation)
  • 10am

* Absolute datetime

  • August 6th
  • 06/05/2009
  • 06.05.2009
  • Feb 28, 4AM
  • 2AM Jun 4
  • 6AM, June 7, 2009
  • 2008-12-01

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDuration

func FormatDuration(duration time.Duration) string

FormatDuration is almost shortcut of the following function call:

FormatRelativeDurationFrom(time.Now(), time.Now().Add(duration))

func FormatDurationFrom

func FormatDurationFrom(src, dst time.Time) string

FormatDurationFrom generates human readable string of time.Duration like GitHub.

Compare with FormatRelativeDurationFrom, it returns "1 day ago" instead of "yesterday".

func FormatRalative

func FormatRalative(date time.Time) string

func FormatRelativeDurationFrom

func FormatRelativeDurationFrom(src, dst time.Time) string

FormatRelativeDurationFrom generates human readable string of time.Duration like GitHub.

For example, duration between src and dst is less than 60 seconds, this function returns "now".

It returns text like "1 minute ago", "5 minutes later", "2 days ago".

func MustParse

func MustParse(value string) time.Time

MustParse is like Parse but panics if the passed valuecannot be parsed. It simplifies safe initialization of global variables holding parsed time.

func Parse

func Parse(value string) (time.Time, error)

Parse accepts contextful date format and returns absolute time.Time value.

func ParseAbsolute

func ParseAbsolute(value string) (time.Time, error)

ParseAbsolute converts absolute datetime into time.Time. Basic idea is same as time.Parse(), but this detects the format of value and convert it automatically.

func ParseAgo

func ParseAgo(value string) (time.Time, error)

ParseAgo parse "xxxx ago" format and returns corresponding absolute datetime.

func ParseRelative

func ParseRelative(value string) (time.Time, error)

ParseRelative returns absolute datetime corresponding to relative date expressed in value.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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