ratadie

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: MIT Imports: 3 Imported by: 1

README

Rata Die: A Go package for representing dates as fixed integers.

Installation

go get bitbucket.org/classroomsystems/ratadie

Usage

See godoc for details.

GoDoc

Other software

Notes on using Rata Die dates with other tools.

MySQL

MySQL supports ordinal dates with a different epoch from Rata Die. To convert a Rata Die N to a MySQL date, use from_days(N+365). To convert a MySQL date D to a Rata Die, use to_days(D)-365.

Python

Python has direct support for Rata Die dates, calling them "proleptic Gregorian ordinals". To convert a Rata Die N to a Python date object, use datetime.date.fromordinal(N). To convert a Python date object D to a Rata Die, use D.toordinal().

Documentation

Overview

Package ratadie represents calendar dates as fixed integers, as specified in Dershowitz and Reingold's Calendrical Calculations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Day

type Day int32

A Day represents a given calendar date as a fixed integer, as specified in Dershowitz and Reingold's Calendrical Calculations. Day(1) is Jan 1 of year 1 in the proleptic Gregorian calendar. Representable dates range from Jun 22, -5879610 to Jul 11, 5879611.

func Date

func Date(year int, month time.Month, day int) Day

Date returns the Day for the given year, month, and day. The result of passing out-of-range month or day values is undefined. Do not use this function for month arithmetic.

func Parse

func Parse(layout, value string) (Day, error)

Parse parses a formatted string and returns the day value it represents. It is a convenience wrapper around time.Parse.

Note that time and location may be specified in the format, but are completely ignored.

func Time

func Time(t time.Time) Day

Time is equivalent to calling Date(t.Date()). Note that time and location are completely ignored.

func Today

func Today() Day

Today returns today's date. It is equivalent to Time(time.Now()).

func (Day) Date

func (rd Day) Date() (year int, month time.Month, day int)

Date returns the Gregorian year, month, and day for rd.

func (Day) Format

func (rd Day) Format(layout string) string

Format is just a convenience for rd.Time().Format(layout)

func (Day) MarshalText added in v1.1.0

func (rd Day) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Day) Time

func (rd Day) Time() time.Time

Time returns a UTC time value for midnight on the day represented by rd.

func (Day) TimeIn

func (rd Day) TimeIn(loc *time.Location) time.Time

TimeIn returns a time value for midnight in the given location on the day represented by rd.

func (*Day) UnmarshalText added in v1.1.0

func (rd *Day) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Day) Weekday

func (rd Day) Weekday() time.Weekday

Weekday returns the day of the week specified by rd.

Jump to

Keyboard shortcuts

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