date

package
v0.0.0-...-c4bfc47 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PatternTranslation = map[string]PatternTranslations{
	"en": {
		DateRegex: `(of )?(the )?((after )?tomorrow|((today|tonight)|(next )?(monday|tuesday|wednesday|thursday|friday|saturday|sunday))|(\d{2}|\d)(th|rd|st|nd)? (of )?(january|february|march|april|may|june|july|august|september|october|november|december)|((\d{2}|\d)/(\d{2}|\d)))`,
		TimeRegex: `(at )?(\d{2}|\d)(:\d{2}|\d)?( )?(pm|am|p\.m|a\.m)`,
	},
	"de": {
		DateRegex: `(von )?(das )?((nach )?morgen|((heute|abends)|(nächsten )?(montag|dienstag|mittwoch|donnerstag|freitag|samstag|sonntag))|(\d{2}|\d)(th|rd|st|nd)? (of )?(januar|februar|märz|april|mai|juli|juli|august|september|oktober|november|dezember)|((\d{2}|\d)/(\d{2}|\d)))`,
		TimeRegex: `(um )?(\d{2}|\d)(:\d{2}|\d)?( )?(pm|am|p\.m|a\.m)`,
	},
	"fr": {
		DateRegex: `(le )?(après )?demain|((aujourd'hui'|ce soir)|(lundi|mardi|mecredi|jeudi|vendredi|samedi|dimanche)( prochain)?|(\d{2}|\d) (janvier|février|mars|avril|mai|juin|juillet|août|septembre|octobre|novembre|décembre)|((\d{2}|\d)/(\d{2}|\d)))`,
		TimeRegex: `(à )?(\d{2}|\d)(:\d{2}|\d)?( )?(pm|am|p\.m|a\.m)`,
	},
	"es": {
		DateRegex: `(el )?((pasado )?mañana|((hoy|esta noche)|(el )?(proximo )?(lunes|martes|miercoles|jueves|viernes|sabado|domingo))|(\d{2}|\d) (de )?(enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre)|((\d{2}|\d)/(\d{2}|\d)))`,
		TimeRegex: `(a )?(las )?(\d{2}|\d)(:\d{2}|\d)?( )?(de )?(la )?(pm|am|p\.m|a\.m|tarde|mañana)`,
	},
	"ca": {
		DateRegex: `(el )?((després )?(de )?demà|((avui|aquesta nit)|(el )?(proper )?(dilluns|dimarts|dimecres|dijous|divendres|dissabte|diumenge))|(\d{2}|\d) (de )?(gener|febrer|març|abril|maig|juny|juliol|agost|setembre|octubre|novembre|desembre)|((\d{2}|\d)/(\d{2}|\d)))`,
		TimeRegex: `(a )?(les )?(\d{2}|\d)(:\d{2}|\d)?( )?(pm|am|p\.m|a\.m)`,
	},
	"nl": {
		DateRegex: `(van )?(de )?((na )?morgen|((vandaag|vanavond)|(volgende )?(maandag|dinsdag|woensdag|donderdag|vrijdag|zaterdag|zondag))|(\d{2}|\d)(te|de)? (vab )?(januari|februari|maart|april|mei|juni|juli|augustus|september|oktober|november|december)|((\d{2}|\d)/(\d{2}|\d)))`,
		TimeRegex: `(om )?(\d{2}|\d)(:\d{2}|\d)?( )?(pm|am|p\.m|a\.m)`,
	},
	"el": {
		DateRegex: `(από )?(το )?((μεθ )?αύριο|((σήμερα|απόψε)|(επόμενη )?(δευτέρα|τρίτη|τετάρτη|πέμπτη|παρασκευή|σάββατο|κυριακή))|(\d{2}|\d)(η)? (of )?(ιανουάριος|φεβρουάριος|μάρτιος|απρίλιος|μάιος|ιούνιος|ιούλιος|αύγουστος|σεπτέμβριος|οκτώβριος|νοέμβριος|δεκέμβριος)|((\d{2}|\d)/(\d{2}|\d)))`,
		TimeRegex: `(at )?(\d{2}|\d)(:\d{2}|\d)?( )?(μμ|πμ|μ\.μ|π\.μ)`,
	},
}

PatternTranslation are the map of regexs in different languages

View Source
var RuleTranslations = map[string]RuleTranslation{
	"en": {
		DaysOfWeek: []string{
			"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday",
		},
		Months: []string{
			"january", "february", "march", "april", "may", "june", "july",
			"august", "september", "october", "november", "december",
		},
		RuleToday:         `today|tonight`,
		RuleTomorrow:      `(after )?tomorrow`,
		RuleAfterTomorrow: "after",
		RuleDayOfWeek:     `(next )?(monday|tuesday|wednesday|thursday|friday|saturday|sunday)`,
		RuleNextDayOfWeek: "next",
		RuleNaturalDate:   `january|february|march|april|may|june|july|august|september|october|november|december`,
	},
	"de": {
		DaysOfWeek: []string{
			"Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag",
		},
		Months: []string{
			"Januar", "Februar", "Marsch", "April", "Mai", "Juni", "Juli",
			"August", "September", "Oktober", "November", "Dezember",
		},
		RuleToday:         `heute|abends`,
		RuleTomorrow:      `(nach )?tomorrow`,
		RuleAfterTomorrow: "nach",
		RuleDayOfWeek:     `(nächsten )?(Montag|Dienstag|Mittwoch|Donnerstag|Freitag|Samstag|Sonntag)`,
		RuleNextDayOfWeek: "nächste",
		RuleNaturalDate:   `Januar|Februar|März|April|Mai|Juli|Juli|August|September|Oktober|November|Dezember`,
	},
	"fr": {
		DaysOfWeek: []string{
			"lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche",
		},
		Months: []string{
			"janvier", "février", "mars", "avril", "mai", "juin", "juillet",
			"août", "septembre", "octobre", "novembre", "décembre",
		},
		RuleToday:         `aujourd'hui|ce soir`,
		RuleTomorrow:      `(après )?demain`,
		RuleAfterTomorrow: "après",
		RuleDayOfWeek:     `(lundi|mardi|mecredi|jeudi|vendredi|samedi|dimanche)( prochain)?`,
		RuleNextDayOfWeek: "prochain",
		RuleNaturalDate:   `janvier|février|mars|avril|mai|juin|juillet|août|septembre|octobre|novembre|décembre`,
	},
	"es": {
		DaysOfWeek: []string{
			"lunes", "martes", "miercoles", "jueves", "viernes", "sabado", "domingo",
		},
		Months: []string{
			"enero", "febrero", "marzo", "abril", "mayo", "junio", "julio",
			"agosto", "septiembre", "octubre", "noviembre", "diciembre",
		},
		RuleToday:         `hoy|esta noche`,
		RuleTomorrow:      `(pasado )?mañana`,
		RuleAfterTomorrow: "pasado",
		RuleDayOfWeek:     `(el )?(proximo )?(lunes|martes|miercoles|jueves|viernes|sabado|domingo))`,
		RuleNextDayOfWeek: "proximo",
		RuleNaturalDate:   `enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre`,
	},
	"ca": {
		DaysOfWeek: []string{
			"dilluns", "dimarts", "dimecres", "dijous", "divendres", "dissabte", "diumenge",
		},
		Months: []string{
			"gener", "febrer", "març", "abril", "maig", "juny", "juliol",
			"agost", "setembre", "octubre", "novembre", "desembre",
		},
		RuleToday:         `avui|aquesta nit`,
		RuleTomorrow:      `((després )?(de )?demà`,
		RuleAfterTomorrow: "després",
		RuleDayOfWeek:     `(el )?(proper )?(dilluns|dimarts|dimecres|dijous|divendres|dissabte|diumenge))`,
		RuleNextDayOfWeek: "proper",
		RuleNaturalDate:   `gener|febrer|març|abril|maig|juny|juliol|agost|setembre|octubre|novembre|desembre`,
	},
	"nl": {
		DaysOfWeek: []string{
			"maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag", "zondag",
		},
		Months: []string{
			"januari", "februari", "maart", "april", "mei", "juni", "juli",
			"augustus", "september", "oktober", "november", "december",
		},
		RuleToday:         `vandaag|vanavond`,
		RuleTomorrow:      `(na )?morgen`,
		RuleAfterTomorrow: "na",
		RuleDayOfWeek:     `(volgende )?(maandag|dinsdag|woensdag|donderdag|vrijdag|zaterdag|zondag)`,
		RuleNextDayOfWeek: "volgende",
		RuleNaturalDate:   `januari|februari|maart|april|mei|juni|juli|augustus|september|oktober|november|december`,
	},
	"el": {
		DaysOfWeek: []string{
			"δευτέρα", "τρίτη", "τετάρτη", "πέμπτη", "παρασκευή", "σάββατο", "κυριακή",
		},
		Months: []string{
			"ιανουάριος", "φεβρουάριος", "μάρτιος", "απρίλιος", "μάιος", "ιούνιος", "ιούλιος",
			"αύγουστος", "σεπτέμβριος", "οκτώβριος", "νοέμβριος", "δεκέμβριος",
		},
		RuleToday:         `σήμερα|απόψε`,
		RuleTomorrow:      `(μεθ )?άυριο`,
		RuleAfterTomorrow: "μεθ",
		RuleDayOfWeek:     `(επόμενη )?(δευτέρα|τρίτη|τετάρτη|πέμπτη|παρασκευή|σάββατο|κυριακή)`,
		RuleNextDayOfWeek: "επόμενη",
		RuleNaturalDate:   `ιανουάριος|φεβρουάριος|μάρτιος|απρίλιος|μάιος|ιούνιος|ιούλιος|αύγουστος|σεπτέμβριος|οκτώβριος|νοέμβριος|δεκέμβριος`,
	},
}

RuleTranslations are the translations of the rules in different languages

Functions

func DeleteDates

func DeleteDates(locale, sentence string) string

DeleteDates removes the dates of the given sentence and returns it

func DeleteTimes

func DeleteTimes(locale, sentence string) string

DeleteTimes removes the times of the given sentence and returns it

func RegisterRule

func RegisterRule(rule Rule)

RegisterRule takes a rule in parameter and register it to the array of rules

func RuleDate

func RuleDate(locale, sentence string) time.Time

RuleDate checks for dates written like mm/dd

func RuleDayOfWeek

func RuleDayOfWeek(locale, sentence string) time.Time

RuleDayOfWeek checks for the days of the week and the keyword "next" in the given sentence, then it returns the date parsed.

func RuleNaturalDate

func RuleNaturalDate(locale, sentence string) time.Time

RuleNaturalDate checks for the dates written in natural language in the given sentence, then it returns the date parsed.

func RuleTime

func RuleTime(sentence string) time.Time

RuleTime checks for an hour written like 9pm

func RuleToday

func RuleToday(locale, sentence string) (result time.Time)

RuleToday checks for today, tonight, this afternoon dates in the given sentence, then it returns the date parsed.

func RuleTomorrow

func RuleTomorrow(locale, sentence string) (result time.Time)

RuleTomorrow checks for "tomorrow" and "after tomorrow" dates in the given sentence, then it returns the date parsed.

func SearchTime

func SearchTime(locale, sentence string) (string, time.Time)

SearchTime returns the found date in the given sentence and the sentence without the date, if no date has been found, it returns an empty date and the given sentence.

Types

type PatternTranslations

type PatternTranslations struct {
	DateRegex string
	TimeRegex string
}

PatternTranslations are the translations of the regexs for dates

type Rule

type Rule func(string, string) time.Time

A Rule is a function that takes the given sentence and tries to parse a specific rule to return a date, if not, the date is empty.

type RuleTranslation

type RuleTranslation struct {
	DaysOfWeek        []string
	Months            []string
	RuleToday         string
	RuleTomorrow      string
	RuleAfterTomorrow string
	RuleDayOfWeek     string
	RuleNextDayOfWeek string
	RuleNaturalDate   string
}

A RuleTranslation is all the texts/regexs to match the dates

Jump to

Keyboard shortcuts

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