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 ¶
- func FormatDuration(duration time.Duration) string
- func FormatDurationFrom(src, dst time.Time) string
- func FormatRalative(date time.Time) string
- func FormatRelativeDurationFrom(src, dst time.Time) string
- func MustParse(value string) time.Time
- func Parse(value string) (time.Time, error)
- func ParseAbsolute(value string) (time.Time, error)
- func ParseAgo(value string) (time.Time, error)
- func ParseRelative(value string) (time.Time, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatDuration ¶
FormatDuration is almost shortcut of the following function call:
FormatRelativeDurationFrom(time.Now(), time.Now().Add(duration))
func FormatDurationFrom ¶
FormatDurationFrom generates human readable string of time.Duration like GitHub.
Compare with FormatRelativeDurationFrom, it returns "1 day ago" instead of "yesterday".
func FormatRalative ¶
func FormatRelativeDurationFrom ¶
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 ¶
MustParse is like Parse but panics if the passed valuecannot be parsed. It simplifies safe initialization of global variables holding parsed time.
func ParseAbsolute ¶
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.
Types ¶
This section is empty.