{"id":19347605,"url":"https://github.com/wessouza/calendar-base","last_synced_at":"2025-04-14T05:54:21.715Z","repository":{"id":27418555,"uuid":"30895855","full_name":"WesSouza/calendar-base","owner":"WesSouza","description":"Base methods for generating calendars using JavaScript.","archived":false,"fork":false,"pushed_at":"2025-02-12T16:42:47.000Z","size":490,"stargazers_count":387,"open_issues_count":1,"forks_count":20,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-04-07T03:01:41.216Z","etag":null,"topics":["calendar","calendar-generator","javascript","library"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WesSouza.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-02-17T00:32:10.000Z","updated_at":"2025-02-12T16:41:40.000Z","dependencies_parsed_at":"2023-12-16T04:27:11.145Z","dependency_job_id":"5b99c737-5f5a-4231-a22b-209039c1bb9e","html_url":"https://github.com/WesSouza/calendar-base","commit_stats":{"total_commits":57,"total_committers":9,"mean_commits":6.333333333333333,"dds":0.5263157894736843,"last_synced_commit":"9b3f5f4f3f36cf0a84befa051000de5a27e7f1dc"},"previous_names":["wesleydesouza/calendar-base"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WesSouza%2Fcalendar-base","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WesSouza%2Fcalendar-base/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WesSouza%2Fcalendar-base/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WesSouza%2Fcalendar-base/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WesSouza","download_url":"https://codeload.github.com/WesSouza/calendar-base/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248830390,"owners_count":21168272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["calendar","calendar-generator","javascript","library"],"created_at":"2024-11-10T04:17:13.586Z","updated_at":"2025-04-14T05:54:21.682Z","avatar_url":"https://github.com/WesSouza.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Calendar Base\n\n[![Lint, Type Check, Test, Build](https://github.com/WesSouza/calendar-base/actions/workflows/lint-typecheck-test-build.yml/badge.svg)](https://github.com/WesSouza/calendar-base/actions/workflows/lint-typecheck-test-build.yml) [![npm version](https://badge.fury.io/js/calendar-base.svg)](https://www.npmjs.com/package/calendar-base)\n\nBase methods for generating calendars using JavaScript.\n\nOutput is ES5 compatible.\n\n## Installation\n\n```bash\n# using npm\nnpm install calendar-base\n\n# or yarn\nyarn add calendar-base\n```\n\n## Usage\n\n```js\nconst Calendar = require('calendar-base').Calendar;\nconst cal = new Calendar();\n\ncal.getCalendar(2020, 0);\n/*\nReturns an Array with the calendar for January 2020, including empty spaces for\ndays from the previous and next months:\n\n[\n  false,\n  false,\n  { day: 1, weekDay: 3, month: 0, year: 2020 },\n  { day: 2, weekDay: 4, month: 0, year: 2020 },\n  { day: 3, weekDay: 5, month: 0, year: 2020 },\n  { day: 4, weekDay: 6, month: 0, year: 2020 },\n  { day: 5, weekDay: 0, month: 0, year: 2020 },\n  ...\n]\n*/\n```\n\n[Check an online example](https://stackblitz.com/edit/js-ad7edj?file=index.js)\nor browse the [`examples`](./examples/) folder for some simple use cases.\n\n### Date object notation\n\nEvery returned day or date argument follows this notation:\n\n```js\n{\n  day: 14,\n  month: 9,\n  year: 1986,\n  weekDay: 4,\n  selected: false,\n  siblingMonth: false,\n  weekNumber: 42\n}\n```\n\nProperties `month` and `weekDay` respect JavaScript’s\n[`Date.prototype`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/prototype).\n\nOnly `day`, `month`, and `year` are necessary as input parameters for methods\nthat require a date.\n\n#### `Calendar(options)`\n\nConstructor for a new calendar generator.\n\nThe object `options` may have the following properties:\n\n- `startDate`: current selected starting date (default `undefined`)\n- `endDate`: current selected ending date (default `undefined`)\n- `siblingMonths`: whether to include the previous and next months’ days before\n  and after the current month when generating a calendar (default `false`)\n- `weekNumbers`: whether to include the week number on each day\n- `weekStart`: day of the week, respects\n  [`Date.prototype.getDay`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay) (default `0`, Sunday)\n\n#### `Calendar.diff(dateOne, dateTwo)`\n\nReturns the difference in days between `dateOne` and `dateTwo` as a `Number`.\n\n```js\n\u003e Calendar.diff({ year: 2010, month: 0, day: 1 }, { year: 2010, month: 0, day: 10 });\n-9\n```\n\n#### `Calendar.interval(dateOne, dateTwo)`\n\nReturns the amount of days between `dateOne` and `dateTwo` as a `Number`.\n\n```js\n\u003e Calendar.interval({ year: 2010, month: 0, day: 1 }, { year: 2010, month: 0, day: 10 });\n10\n```\n\n#### `Calendar.compare(leftDate, rightDate)`\n\nCompares two date objects, returns:\n\n- `-1` if `leftDate` \u003c `rightDate`\n- `0` if `leftDate` == `rightDate`\n- `1` if `leftDate` \u003e `rightDate`\n\nUseful for quick comparisons such as sorting an array of dates.\n\n```js\n\u003e Calendar.compare({ year: 2010, month: 0, day: 1 }, { year: 2010, month: 0, day: 10 });\n1\n```\n\n#### `Calendar.daysInMonth(year, month)`\n\nReturns the amount of days in the given month as a `Number`.\n\n```js\n\u003e Calendar.daysInMonth(2010, 0);\n31\n```\n\n#### `Calendar.isLeapYear(year)`\n\nReturns whether the given year is a leap year, as a `Boolean`.\n\n```js\n\u003e Calendar.isLeapYear(2100);\nfalse\n```\n\n#### `Calendar.calculateWeekNumber(date)`\n\nReturns the week number for the specified date.\n\n```js\n\u003e Calendar.calculateWeekNumber({year: 1986, month: 9, day: 14 });\n42\n```\n\n#### `Calendar.prototype.getCalendar(year, month)`\n\nReturns an `Array` of dates with the days from the given month, always starting\nat the configured week day.\n\nIf sibling months is disabled, paddings are added as `false` to align the week\ndays, otherwise the respective days from the previous or next months are\nincluded.\n\n```js\n\u003e var cal = new Calendar({ siblingMonths: true });\n\u003e cal.getCalendar(2015, 5);\n[ { day: 31, weekDay: 0, month: 4, year: 2015, siblingMonth: true },\n  { day: 1, weekDay: 1, month: 5, year: 2015 },\n  { day: 2, weekDay: 2, month: 5, year: 2015 },\n  ...\n  { day: 4, weekDay: 6, month: 6, year: 2015, siblingMonth: true } ]\n```\n\n#### `Calendar.prototype.setDate(date)`\n\nAlias to `Calendar.prototype.setStartDate`.\n\n#### `Calendar.prototype.setStartDate(date)`\n\nSets the current selected starting date.\n\n```js\n\u003e cal.setStartDate({ year: 2015, month: 0, day: 1 });\n```\n\n#### `Calendar.prototype.setEndDate(date)`\n\nSets the current selected ending date.\n\n```js\n\u003e cal.setEndDate({ year: 2015, month: 0, day: 31 });\n```\n\n#### `Calendar.prototype.isDateSelected(date)`\n\nChecks whether the given date is inside the selected dates interval, returns a\n`Boolean`.\n\n```js\n\u003e cal.isDateSelected({ year: 2015, month: 0, day: 10 });\ntrue\n```\n\n## Important note on week numbers\n\nWeek numbers are calculated based on the ISO 8601 standard, which assumes\ncalculations based on weeks starting on Mondays. Be extra careful displaying the\nweek number if your calendar doesn't start on a Monday.\n\n## Development\n\nThis library uses `wes-cli`, which simplifies configuration setup. Instead of\nusing `yarn install`, you should use `npx wes-cli install`, which will create\nall configuration files and run `yarn install`.\n\n[Read more about `wes-cli`.](https://github.com/WesSouza/wes-cli/#wes-install)\n\n## License\n\nMIT, https://wes.dev/LICENSE.txt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwessouza%2Fcalendar-base","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwessouza%2Fcalendar-base","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwessouza%2Fcalendar-base/lists"}