calendar

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: MIT Imports: 2 Imported by: 0

README

calendar

Go Reference GolangCI Lint

Provide basic operations on calendars in Go.

Install

go get -u github.com/edgelaboratories/calendar

Requirements

Test

Run the following:

make test

Check out the Makefile for more information.

Purpose

This project aims at offering a unique, simple and fast module to manage calendars with daily granularity. Dates representation is based on github.com/edgelaboratories/date.

This project doesn't aim at supporting daycount conventions. Have a look at github.com/edgelaboratories/daycount instead.

Usage

package main

import (
    "fmt"
    "github.com/edgelaboratories/calendar"
    "github.com/edgelaboratories/date"
)

func main() {
    c := calendar.New(calendar.BusinessDays)

    fmt.Println(c.Convention()) // output is "BusinessDays"
    
    fmt.Println(c.DaysBetween(
        date.New(2021, time.October, 13), // Wednesday
        date.New(2021, time.October, 15), // Friday
    )) // output is 2

    fmt.Println(c.Add(
        date.New(2021, time.October, 13), // Wednesday
        2,
    ).String()) // output is Friday "2021-10-15"
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Calendar

type Calendar struct {
	// contains filtered or unexported fields
}

Calendar exposes functions to manipulate dates with respect to a calendar.

func New

func New(convention Convention) *Calendar

New returns a calendar based on the specified input convention.

func (*Calendar) LatestBefore

func (c *Calendar) LatestBefore(date date.Date) date.Date

LatestBefore returns the latest date before or equal to an input date. As opposed to the input date, the output date belongs to the calendar by construction.

func (*Calendar) Next added in v0.6.0

func (c *Calendar) Next(date date.Date) date.Date

Next returns the next calendar date with respect to the input.

func (*Calendar) Previous added in v0.6.0

func (c *Calendar) Previous(date date.Date) date.Date

Previous returns the previous calendar date with respect to the input.

type Convention

type Convention string

Convention defines the calendar convention.

const (
	// BusinessDays uses a no-holiday calendar.
	// Only working days are active, weekends are neglected.
	BusinessDays Convention = "BusinessDays"
	// CalendarDays defines a convention that uses a nominal ISO calendar.
	// All days, including weekends, are considered active.
	CalendarDays Convention = "CalendarDays"
)

Jump to

Keyboard shortcuts

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