brimtime

package module
v0.0.0-...-42a185f Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2019 License: BSD-3-Clause Imports: 5 Imported by: 30

README

BrimTime

Date and Time Tools for Go

Package brimtime contains tools for working with dates and times.

API Documentation

Copyright See AUTHORS. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.

Documentation

Overview

Package brimtime contains tools for working with dates and times.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtForString

func AtForString(hour int, minute int, duration int) string

AtForString formats the hour, minute, and duration (in minutes) into a concise display string, such as: "@11:00" "@15:30 for 30m" "for 2h"

func NearDateString

func NearDateString(reference time.Time, now time.Time) string

NearDateString returns a string that represents the date, with less resolution the nearer it is to now (e.g. "Thursday, the 4th of July, 2013" "Thursday the 4th"). If now.IsZero() then time.Now() will be used.

func SameDay

func SameDay(left time.Time, right time.Time) bool

SameDay returns true if the two times are on the same day.

func StartOfMonth

func StartOfMonth(reference time.Time) time.Time

StartOfMonth returns a time for the beginning of the month, the 1st, at the same time as the reference.

func StartOfWeek

func StartOfWeek(reference time.Time) time.Time

StartOfWeek returns a time for the beginning of the week, Sunday, at the same time as the reference.

func TimeToUnixMicro

func TimeToUnixMicro(t time.Time) int64

TimeToUnixMicro returns the time as a count of microseconds within the Unix epoch.

func TranslateDateRef

func TranslateDateRef(value string, biases []string, reference time.Time) time.Time

TranslateDateRef returns the time.Time the value represents with undetermined items filled in from the reference time.

The biases list is for the call to TranslateYMD that is made, see there for more detail but the a common setting is []string{"", "D", "MD", "YMD"}.

Note that only the date is detected with this function; any time information in the value will be ignored.

func TranslateMonth

func TranslateMonth(value string) int

TranslateMonth returns the month the value represents, or 0 if it cannot be determined. The value may be a month name, prefix, number (e.g. "August" "Aug" "8" "08") and is not case sensitive.

func TranslateRelativeDate

func TranslateRelativeDate(value string, reference time.Time) time.Time

TranslateRelativeDate returns the time the value represents with undetermined items filled in from the reference time. The value may be various relative expressions, such as: "tomorrow", "last week", "3 weeks from now", "five days ago", etc. If the value cannot be parsed correctly, time.IsZero() will be returned.

func TranslateWeekday

func TranslateWeekday(value string) int

TranslateWeekday returns the weekday the value represents, or -1 if it cannot be determined. The value may be a weekday name, prefix, or number (e.g. "Monday" "Mon" "1" "01") and is not case sensitive.

func TranslateYMD

func TranslateYMD(value string, biases []string) (int, int, int)

TranslateYMD returns the year, month, and day the value represents, or zeros for the parts that cannot be determined. The biases field indicates the priority to use when guesses must be made. For example, if the value is "1-2-3", a bias of "YMD" would return 1, 2, 3 but a bias of "MDY" would return 3, 1, 2. Each bias in the list of biases is for that number of items given in the value. For example, "1-2-3" would use biases[3] as the bias, "1-2" would use biases[2], etc.; therefore the biases list should be four elements long.

The value can be of various formats, but boils down to 1-3 items separated by one of the following characters "-/., ". Each item can represent a year, month, or day and the months can be numbers, names, or prefixes. Some examples: "1-2-2014" "2-Jan-2014" "January 2, 2014" "2,jan"

A common call would be: TranslateYMD(value, []string{"", "D", "MD", "YMD"})

func UnixMicroToTime

func UnixMicroToTime(t int64) time.Time

UnixMicroToTime returns the time for a given count of microseconds within the Unix epoch.

Types

This section is empty.

Jump to

Keyboard shortcuts

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