All Projects → rickar → Cal

rickar / Cal

Licence: bsd-3-clause
Go (golang) calendar library for dealing with holidays and work days

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Labels

Projects that are alternatives of or similar to Cal

Life Calendar
A look at the big picture.
Stars: ✭ 139 (-12.03%)
Mutual labels:  calendar
Moment Hijri
A Hijri calendar (Based on Umm al-Qura calculations) plugin for moment.js
Stars: ✭ 144 (-8.86%)
Mutual labels:  calendar
Wx calendar
微信小程序-日历组件 📅
Stars: ✭ 2,008 (+1170.89%)
Mutual labels:  calendar
Zbjcalendar
ZBJCalendar is a simple calendar framework for iOS.
Stars: ✭ 140 (-11.39%)
Mutual labels:  calendar
Flutter Timeline
⌚️ A general flutter timeline widget based on real-world application references
Stars: ✭ 142 (-10.13%)
Mutual labels:  calendar
Wrcalendarview
Calendar Day and Week View for iOS
Stars: ✭ 147 (-6.96%)
Mutual labels:  calendar
Openki
We moved to GitLab 💔 Openki is a tool to build up and organize local communities – Open education for real.
Stars: ✭ 137 (-13.29%)
Mutual labels:  calendar
Time To Leave
Log work hours and get notified when it's time to leave the office and start to live.
Stars: ✭ 155 (-1.9%)
Mutual labels:  calendar
Calendarkit
📅 Calendar for Apple platforms in Swift
Stars: ✭ 2,049 (+1196.84%)
Mutual labels:  calendar
Chinese Lunar Calendar For Mac
Chinese Lunar Calendar for Mac
Stars: ✭ 150 (-5.06%)
Mutual labels:  calendar
Timetable
📅 Customizable flutter calendar widget including day and week views
Stars: ✭ 140 (-11.39%)
Mutual labels:  calendar
React Calendar
React.js Calendar Component (npm install react-calendar-component) 📅
Stars: ✭ 142 (-10.13%)
Mutual labels:  calendar
Alfred Gcal
View Google Calendar events in Alfred
Stars: ✭ 147 (-6.96%)
Mutual labels:  calendar
Tail.datetime
A lightweight, translat- and configurable Open Source DateTime Picker, written in pure vanilla JavaScript!
Stars: ✭ 139 (-12.03%)
Mutual labels:  calendar
Air Datepicker
Lightweight, dependency-free JavaScript datepicker.
Stars: ✭ 1,913 (+1110.76%)
Mutual labels:  calendar
React Calendar
Ultimate calendar for your React app.
Stars: ✭ 2,082 (+1217.72%)
Mutual labels:  calendar
React Native Dates
React Native date / daterange picker and calendar
Stars: ✭ 145 (-8.23%)
Mutual labels:  calendar
Diary
Android personal diary - forked from http://git.savannah.gnu.org/cgit/diary.git
Stars: ✭ 158 (+0%)
Mutual labels:  calendar
Calendar Ios
Calendar View
Stars: ✭ 154 (-2.53%)
Mutual labels:  calendar
Quasar Ui Qcalendar
QCalendar - Quasar App Extension, Vue CLI plug-in and UMD distributions available
Stars: ✭ 148 (-6.33%)
Mutual labels:  calendar

cal/v2: Go (golang) calendar library for dealing with holidays and work days

This library augments the Go time package to provide easy handling of holidays and work days (business days).

Holiday instances are calculated from either builtin or user-created functions to support exact days, floating days such as the 3rd Monday of the month, yearly offsets such as the 100th day of the year, or more complex rules such as offsets from Easter. Holidays may provide separate actual and observed dates for cases where holidays are celebrated on an alternate day if they fall on a specific day of the week (usually weekends).

The Calendar type provides the basic functionality for creating a yearly calendar with holidays.

BusinessCalendar adds additional functionality for calculating workdays and hours worked.

Differences from v1

For v2, much of the functionality of this library was rewritten to address shortcomings of the v1 releases. This version provides the following benefits over v1:

  • Holidays
    • Observation rules are tied to individual holidays rather than a per-calendar setting
    • Name, description, and observance type fields added
    • Starting, ending, and exception year options
    • Holiday definitions are separated into subpackages by ISO code (no longer necessary to bundle all holidays in the final binary)
  • Calendar
    • Separation of business specific functionality into BusinessCalendar
    • Name and description fields added
    • Support for time.Location matching to ease use of multiple Calendars
  • BusinessCalendar
    • Full support for working hours and related calculations
    • Work days and work start and end times can be provided by custom functions

Example

Here is a simple usage example of a cron job that runs once per day:

package main

import (
	"time"

	"github.com/rickar/cal/v2"
	"github.com/rickar/cal/v2/us"
)

func main() {
	c := cal.NewBusinessCalendar()
	c.Name = "Bigco, Inc."
	c.Description = "Default company calendar"

	// add holidays that the business observes
	c.AddHoliday(
		us.NewYear,
		us.MemorialDay,
		us.IndependenceDay,
		us.LaborDay,
		us.ThanksgivingDay,
		us.ChristmasDay,
	)

	// change the default of a Mon - Fri, 9am-5pm work week
	c.SetWorkday(time.Saturday, true)
	c.SetWorkHours(8*time.Hour, 18*time.Hour+30*time.Minute)

	t := time.Now()

	// run different batch processing jobs based on the day

	if c.IsWorkday(t) {
		// create daily activity reports
	}

	if cal.IsWeekend(t) {
		// validate employee time submissions
	}

	if c.WorkdaysRemain(t) == 10 {
		// 10 business days before the end of month
		// send account statements to customers
	}

	if c.WorkdaysRemain(t) == 0 {
		// last business day of the month
		// execute auto billing transfers
	}

	// determine the number of working hours left in the current month
	nextMonth := cal.DayStart(cal.MonthStart(t.AddDate(0, 1, 0)))
	hoursLeft := c.WorkHoursInRange(t, nextMonth)

	// check if there are any tasks for this month that are in danger of missing their deadline
	pendingTasks := []struct{ pendingHours time.Duration }{{pendingHours: 32}} // assumed to be fetched from a DB or API
	for _, task := range pendingTasks {
		if hoursLeft < task.pendingHours {
			// send alert to management
		}
	}
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].