birthday

package module
v0.0.0-...-140aeec Latest Latest
Warning

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

Go to latest
Published: May 6, 2023 License: BSD-3-Clause Imports: 13 Imported by: 0

README

birthday

A birthday and special day reminder system

Documentation

Overview

Package birthday contains routines for tracking birthdays.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Currently yearly, 100 months, 100 weeks, 1000 days.
	DefaultPeriods = []Period{
		{Years: 1},
		{Months: 100},
		{Weeks: 100},
		{Days: 1000},
	}
)

Functions

func HasYear

func HasYear(t time.Time) bool

HasYear returns true if t has a year. That is t falls on or after 1 Jan 0001

func Parse

func Parse(s string) (parsed time.Time, err error)

Parse converts s to a time in UTC. s must be of form MM/dd/yyyy or MM/dd. If s is of form MM/dd, the year of returned time is 0. s must be a valid date as no normalizing is done. Invalid dates like '08/32/2006' return an error.

func Query

func Query(query string) func(entry Entry) bool

Query returns a function that returns true if the Entry instance passed to it matches query.

func Read

func Read(r io.Reader, consumer consume2.Consumer[Entry]) error

Read reads a birthday file. consumer consumes Entry instances.

func ReadFile

func ReadFile(filename string, consumer consume2.Consumer[Entry]) error

ReadFile reads a birthday file. consumer consumes Entry instances.

func Remind

func Remind(
	entries []Entry,
	periods []Period,
	current time.Time,
	consumer consume2.Consumer[Milestone])

Remind sends an infinite stream of Milestone instances to consumer for the specified entries and periods starting at the date specified by current. Remind sends Milestone instances to consumer in chronological order.

func ToString

func ToString(t time.Time) string

ToString returns t as MM/dd/yyyy or as just MM/dd if t falls before 1 Jan 0001.

func ToStringWithWeekDay

func ToStringWithWeekDay(t time.Time) string

ToStringWithWeekDay works like ToString but adds weekday. ToStringWithWeekDay returns a string such as 'Mon 01/02/2006'. ToStringWithWeekDay panics if t falls before 1 Jan 0001.

func Today

func Today() time.Time

Today returns today's date at midnight in UTC.

Types

type Entry

type Entry struct {
	Name     string
	Birthday time.Time
}

Entry represents a single entry in the birthday database

func EntriesSortedByName

func EntriesSortedByName(entries []Entry) []Entry

EntriesSortedByName returns entries sorted by name while leaving the original entries slice unchanged.

type Milestone

type Milestone struct {

	// The person having the milestone
	Entry

	// The date of the milestone day
	Date time.Time

	// How many days in the future this milestone day is.
	DaysAway int

	// The age of the person on this mileestone day.
	Age Period

	// If true, age is unknown
	AgeUnknown bool
}

Milestone represents a milestone day.

func (*Milestone) AgeString

func (m *Milestone) AgeString() string

AgeString returns the age as a string e.g "57 years"

func (*Milestone) Less

func (m *Milestone) Less(other *Milestone) bool

Less orders Milestones. Less orders first by DaysAway then by Name then by AgeUnknown and finally by Age.

type Period

type Period struct {
	Years  int
	Months int
	Weeks  int
	Days   int

	// If true, Multiply normalizes.
	Normalize bool
}

Period represents a period of time

func (Period) Add

func (p Period) Add(start time.Time, count int) time.Time

Add adds count of this period to start and returns the result.

func (Period) Diff

func (p Period) Diff(end, start time.Time) int

Diff returns the number of this period between end and start rounded down. Diff panics if this period is not valid.

func (Period) Less

func (p Period) Less(other Period) bool

Less orders Periods. Less orders first by Days, then by Weeks, then by Months, and finally by Years.

func (Period) Multiply

func (p Period) Multiply(count int) Period

Multiply returns p * count. If p.Normalize is true, the returned period is normalized. The Normalize field of returned Period is set to false.

func (Period) String

func (p Period) String() string

func (Period) Valid

func (p Period) Valid() bool

Valid returns true if p represents a net positive period.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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