All Projects → WesSouza → Calendar Base

WesSouza / Calendar Base

Licence: mit
Base methods for generating calendars using JavaScript.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Calendar Base

Calendarview
Calendar View Library
Stars: ✭ 71 (-79.24%)
Mutual labels:  library, calendar
Material Calendar View
📅 Material Design Calendar compatible with API 11+
Stars: ✭ 360 (+5.26%)
Mutual labels:  library, calendar
Fscalendar
A fully customizable iOS calendar library, compatible with Objective-C and Swift
Stars: ✭ 9,829 (+2773.98%)
Mutual labels:  library, calendar
Monthyearpicker
Fancy year and month picker library for your android app
Stars: ✭ 36 (-89.47%)
Mutual labels:  library, calendar
Rrule
JavaScript library for working with recurrence rules for calendar dates as defined in the iCalendar RFC and more.
Stars: ✭ 2,249 (+557.6%)
Mutual labels:  library, calendar
Yandex Music Api
Неофициальная Python библиотека для работы с API сервиса Яндекс.Музыка
Stars: ✭ 335 (-2.05%)
Mutual labels:  library
Wuss Weapp
🐳wuss-weapp 一款高质量,组件齐全,高自定义的微信小程序UI组件库
Stars: ✭ 338 (-1.17%)
Mutual labels:  calendar
Towel
Throw in the towel.
Stars: ✭ 333 (-2.63%)
Mutual labels:  library
Portal Lite
Multi-platform Personalized Portal: Web, Browser Extension. All components are web apps--users can compose their own Portal freely, and developers can contribute to the Privoce Web App library to easily incorporate their web app to our Portal.
Stars: ✭ 335 (-2.05%)
Mutual labels:  calendar
Td
Cross-platform library for building Telegram clients
Stars: ✭ 4,260 (+1145.61%)
Mutual labels:  library
Cvcalendar
A custom visual calendar for iOS 8+ written in Swift (>= 4.0).
Stars: ✭ 3,435 (+904.39%)
Mutual labels:  calendar
Bicbucstriim
BicBucStriim streams books, digital books. It fills a gap in the functionality of current NAS devices that provide access to music, videos and photos -- but not books. BicBucStriim fills this gap and provides web-based access to your e-book collection.
Stars: ✭ 336 (-1.75%)
Mutual labels:  library
Collapsible Calendar View Android
Collapsible CalendarView is a simple calendar view which can be collapsed to save space and can be expanded when needed
Stars: ✭ 336 (-1.75%)
Mutual labels:  library
Delaunay Triangulation
C++ version the delaunay triangulation
Stars: ✭ 339 (-0.88%)
Mutual labels:  library
Sectionedslider
iOS 11 Control Center Slider
Stars: ✭ 336 (-1.75%)
Mutual labels:  library
Go Grpc Middleware
Golang gRPC Middlewares: interceptor chaining, auth, logging, retries and more.
Stars: ✭ 4,170 (+1119.3%)
Mutual labels:  library
Fb2cal
Fetch Facebook Birthdays events and create an ICS file for use with calendar apps
Stars: ✭ 335 (-2.05%)
Mutual labels:  calendar
Cordova Plugin Media
Apache Cordova Plugin media
Stars: ✭ 338 (-1.17%)
Mutual labels:  library
2019 Typography Calendar
2019 字体日历 App
Stars: ✭ 342 (+0%)
Mutual labels:  calendar
Easyreveal
Android Easy Reveal Library
Stars: ✭ 338 (-1.17%)
Mutual labels:  library

Calendar Base

CI Tests status badge npm version

Base methods for generating calendars using JavaScript.

Output is ES5 compatible.

Installation

# using npm
npm install calendar-base

# or yarn
yarn add calendar-base

Usage

const Calendar = require('calendar-base').Calendar;
const cal = new Calendar();

cal.getCalendar(2020, 0);
/*
Returns an Array with the calendar for January 2020, including empty spaces for
days from the previous and next months:

[
  false,
  false,
  { day: 1, weekDay: 3, month: 0, year: 2020 },
  { day: 2, weekDay: 4, month: 0, year: 2020 },
  { day: 3, weekDay: 5, month: 0, year: 2020 },
  { day: 4, weekDay: 6, month: 0, year: 2020 },
  { day: 5, weekDay: 0, month: 0, year: 2020 },
  ...
]
*/

Check an online example or browse the examples folder for some simple use cases.

Date object notation

Every returned day or date argument follows this notation:

{
  day: 14,
  month: 9,
  year: 1986,
  weekDay: 4,
  selected: false,
  siblingMonth: false,
  weekNumber: 42
}

Properties month and weekDay respect JavaScript’s Date.prototype.

Only day, month, and year are necessary as input parameters for methods that require a date.

Calendar(options)

Constructor for a new calendar generator.

The object options may have the following properties:

  • startDate: current selected starting date (default undefined)
  • endDate: current selected ending date (default undefined)
  • siblingMonths: whether to include the previous and next months’ days before and after the current month when generating a calendar (default false)
  • weekNumbers: whether to include the week number on each day
  • weekStart: day of the week, respects Date.prototype.getDay (default 0, Sunday)

Calendar.diff(dateOne, dateTwo)

Returns the difference in days between dateOne and dateTwo as a Number.

> Calendar.diff({ year: 2010, month: 0, day: 1 }, { year: 2010, month: 0, day: 10 });
-9

Calendar.interval(dateOne, dateTwo)

Returns the amount of days between dateOne and dateTwo as a Number.

> Calendar.interval({ year: 2010, month: 0, day: 1 }, { year: 2010, month: 0, day: 10 });
10

Calendar.compare(leftDate, rightDate)

Compares two date objects, returns:

  • -1 if leftDate < rightDate
  • 0 if leftDate == rightDate
  • 1 if leftDate > rightDate

Useful for quick comparisons such as sorting an array of dates.

> Calendar.compare({ year: 2010, month: 0, day: 1 }, { year: 2010, month: 0, day: 10 });
1

Calendar.daysInMonth(year, month)

Returns the amount of days in the given month as a Number.

> Calendar.daysInMonth(2010, 0);
31

Calendar.isLeapYear(year)

Returns whether the given year is a leap year, as a Boolean.

> Calendar.isLeapYear(2100);
false

Calendar.calculateWeekNumber(date)

Returns the week number for the specified date.

> Calendar.calculateWeekNumber({year: 1986, month: 9, day: 14 });
42

Calendar.prototype.getCalendar(year, month)

Returns an Array of dates with the days from the given month, always starting at the configured week day.

If sibling months is disabled, paddings are added as false to align the week days, otherwise the respective days from the previous or next months are included.

> var cal = new Calendar({ siblingMonths: true });
> cal.getCalendar(2015, 5);
[ { day: 31, weekDay: 0, month: 4, year: 2015, siblingMonth: true },
  { day: 1, weekDay: 1, month: 5, year: 2015 },
  { day: 2, weekDay: 2, month: 5, year: 2015 },
  ...
  { day: 4, weekDay: 6, month: 6, year: 2015, siblingMonth: true } ]

Calendar.prototype.setDate(date)

Alias to Calendar.prototype.setStartDate.

Calendar.prototype.setStartDate(date)

Sets the current selected starting date.

> cal.setStartDate({ year: 2015, month: 0, day: 1 });

Calendar.prototype.setEndDate(date)

Sets the current selected ending date.

> cal.setEndDate({ year: 2015, month: 0, day: 31 });

Calendar.prototype.isDateSelected(date)

Checks whether the given date is inside the selected dates interval, returns a Boolean.

> cal.isDateSelected({ year: 2015, month: 0, day: 10 });
true

Important note on week numbers

Week numbers are calculated based on the ISO 8601 standard, which assumes calculations based on weeks starting on Mondays. Be extra careful displaying the week number if your calendar doesn't start on a Monday.

License

MIT, https://wes.dev/LICENSE.txt

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].