bitcal

package module
v0.0.0-...-a904340 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

README

bitcal

import "github.com/cxtuttle/go-bitcal"

API documentation

bitcal provides 2 functions, one to add work days to a date and another to compute the delta work days between 2 dates. Inspiration was taken from Date::Calendar.

Examples

	bc := bitcal.Create(bitcal.USWorkDays, bitcal.Holidays{})

	start_date := time.Date(2009, 1, 4, 0, 0, 0, 0, time.UTC)

	new_date := bc.AddWorkDays(start_date, -55)
	bc := bitcal.Create(bitcal.USWorkDays, bitcal.Holidays{})

	start_date := time.Date(2019, 8, 4, 0, 0, 0, 0, time.UTC)
	end_date := time.Date(2021, 1, 13, 0, 0, 0, 0, time.UTC)

	delta := bc.DeltaWorkDays(start_date, end_date)

Documentation

Overview

Package bitcal provides functions for doing date math with business calendars. It uses bit vectors to track working days from non-working days.

Index

Constants

This section is empty.

Variables

View Source
var USWorkDays = Workdays{true, true, true, true, true, false, false}

Predefined Workdays type for the US work week. Mon-Fri are marked true.

Functions

This section is empty.

Types

type BitCal

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

func Create

func Create(wd Workdays, hd Holidays) (c *BitCal)

Create takes a Workday and Holidays struct and returns an initialized struct in return that can be used for calls against that Calendar.

func (*BitCal) AddWorkDays

func (c *BitCal) AddWorkDays(date time.Time, days int, include bool) (ret_date time.Time)

AddWorkDays take a starting time.Time and the number of work days( positive or negative ) to add to the date. When include is true, the current date is included and if it is a non work-day it will the not skip the forwards/backwords work-day. A time.Time is returned.

func (*BitCal) DeltaWorkDays

func (c *BitCal) DeltaWorkDays(date1 time.Time, date2 time.Time) (days int)

DeltaWorkDays takes two time.Time's and returns the number of work days between them.

func (*BitCal) IsWorkDay

func (c *BitCal) IsWorkDay(date time.Time) (ret bool)

IsWorkDay returns true if the date given is a work day

func (*BitCal) WorkDayNextIncl

func (c *BitCal) WorkDayNextIncl(date time.Time) (ret_date time.Time)

WorkDayNextIncl take a starting time.Time and returns the Next Workday Including the date given. A time.Time is returned.

func (*BitCal) WorkDayPrevIncl

func (c *BitCal) WorkDayPrevIncl(date time.Time) (ret_date time.Time)

WorkDayPrevIncl take a starting time.Time and returns the Previous Workday Including the date given. A time.Time is returned.

type Holidays

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

TODO: The Holidays type will eventually add holiday support. The dates here will be omitted from a work calendar. Expect type to change.

type Workdays

type Workdays struct {
	Mon bool
	Tue bool
	Wed bool
	Thu bool
	Fri bool
	Sat bool
	Sun bool
}

Workdays type is used to assign whether a given day is a workday. Assign true to a day to indicate it is a workday.

Jump to

Keyboard shortcuts

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