Giter Club home page Giter Club logo

calendar's Introduction

calendar

Build Status Coverage Status

A simple Go library to calculate recurring appointment dates within a time period. Supports all types of recurrences in Outlook and Google calendar

Getting Started

go get https://github.com/robarchibald/calendar
  1. Create a Recurrence Struct (normally pulled from database)
  2. call GetOccurrences(startTime, endTime)
// Every 4th weekday
startTime := time.Date(2016, 1, 1, 12, 30, 0, 0, time.UTC)
dailyIsOnlyWeekday := true
r := Recurrence{
	StartDate: 	           startTime,
	RecurrencePatternCode: "D",
	RecurEvery:            4,
	DailyIsOnlyWeekday:    &dailyIsOnlyWeekday}
occurrences := r.GetOccurrences(startTime, startTime.AddDate(0, 1, 0))

For additional examples, see recurrence_test.go

Notes about the Recurrence Struct

The Recurrence struct is modeled after the recurring schedule data model used by both Microsoft Outlook and Google Calendar for recurring appointments. Just like Outlook, you can pick from Daily ("D"), Weekly ("W"), Monthly ("M") and Yearly ("Y") recurrence pattern codes. Each of those recurrence patterns then require the corresponding information to be filled in.

All recurrences:

  • StartDateTime - start time of the appointment. Should be set to the first desired occurence of the recurring appointment
  • RecurrencePatternCode - D: daily, W: weekly, M: monthly or Y: yearly
  • RecurEvery - number defining how many days, weeks, months or years to wait between recurrences
  • EndByDate (optional) - date by which recurrences must be done by
  • NumberOfOccurrences (optional) - data for UI which can be used to store the number of recurrences. Has no effect in calculations though. EndByDate must be calculated based on NumberOfOccurrences

Recurrence Pattern Code D (daily)

  • DailyIsOnlyWeekday (optional) - ensure that daily occurrences only fall on weekdays (M, T, W, Th, F)

Recurrence Pattern Code W (weekly)

  • WeeklyDaysIncluded - binary value (converted to int16) to indicate days included (e.g. 0101010 or decimal 42 would be MWF). Each of the individual days are bitwise AND'd together to get the value.
    • Sunday - 64 (1000000)
    • Monday - 32 (0100000)
    • Tuesday - 16 (0010000)
    • Wednesday - 8 (0001000)
    • Thursday - 4 (0000100)
    • Friday - 2 (0000010)
    • Saturday - 1 (0000001)

Recurrence Pattern Code M (monthly)

  • MonthlyWeekOfMonth - week of the month to recur on. e.g. Thanksgiving is always on the 4th week of the month. Must be used together with MonthlyDayOfWeek
  • MonthlyDayOfWeek - day of the week to recur on (0=Sunday, 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday). Must be used together with MonthlyWeekOfMonth OR
  • MonthlyDay - day of the month to recur on. e.g. 5 would recur on the 5th of every month

Recurrence Pattern Code Y (yearly)

  • YearlyMonth - month of the year to recur on (1=January, 2=February, 3=March, 4=April, 5=May, 6=June, 7=July)
  • MonthlyWeekOfMonth - week of the month to recur on. e.g. Thanksgiving is always on the 4th week of the month. Note: in order to get the last week of the month, use 54 (which can be remembered by thinking take the 5th week unless it doesn't exist, then use 4th week). Must be used together with MonthlyDayOfWeek
  • MonthlyDayOfWeek - day of the week to recur on (0=Sunday, 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday). Must be used together with MonthlyWeekOfMonth OR
  • MonthlyDay - day of the month to recur on. e.g. 5 would recur on the 5th of every month

Outlook Recurrence Setup

calendar's People

Contributors

robarchibald avatar scullwm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.