dateparse

package module
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2021 License: Unlicense Imports: 6 Imported by: 1

README

Codecov coveragei build codecov

dateparse

Лёгкий способ превратить пользовательский ввод даты во что-то машинопонятное.

Пользователи такие затейники, чего только не вводят, но мы пытаемся всё понять и простить:

package main 

import (
    "time"
    "github.com/tada-team/dateparse"
)

func main() {
    date, message := dateparse.Parse("в следующий понедельник утром посмотреть код", nil)
    if date.IsZero() {
        panic("invalid date")
    }
    print("at:", date)
    print("do:", message)

    loc, err := time.LoadLocation("Europe/Moscow")
    if err != nil {
        panic(err)
    } 
    date, _ = dateparse.Parse("завтра", &dateparse.Opts{
        TodayEndHour: 20,
        Now:          time.Now().In(loc),
    })
    print(date)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(s string, opts *Opts) (time.Time, string)

Types

type Opts

type Opts struct {
	TodayEndHour int
	Now          time.Time
}

Jump to

Keyboard shortcuts

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