{"id":15983184,"url":"https://github.com/perry-mitchell/date-matrix","last_synced_at":"2026-03-11T17:31:38.057Z","repository":{"id":57211537,"uuid":"363928309","full_name":"perry-mitchell/date-matrix","owner":"perry-mitchell","description":"Calendar date matrix generator","archived":false,"fork":false,"pushed_at":"2021-05-03T19:11:32.000Z","size":43,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T07:22:35.409Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/perry-mitchell.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-03T12:51:15.000Z","updated_at":"2021-05-07T23:15:10.000Z","dependencies_parsed_at":"2022-08-30T13:11:53.222Z","dependency_job_id":null,"html_url":"https://github.com/perry-mitchell/date-matrix","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perry-mitchell%2Fdate-matrix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perry-mitchell%2Fdate-matrix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perry-mitchell%2Fdate-matrix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perry-mitchell%2Fdate-matrix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/perry-mitchell","download_url":"https://codeload.github.com/perry-mitchell/date-matrix/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252831176,"owners_count":21810779,"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":[],"created_at":"2024-10-08T01:41:01.379Z","updated_at":"2025-10-19T08:35:24.918Z","avatar_url":"https://github.com/perry-mitchell.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Date Matrix\n\u003e Calendar date matrix generator\n\n[![NPM version](https://img.shields.io/npm/v/date-matrix?color=green)](https://www.npmjs.com/package/date-matrix)\n\nDate matrix generator for NodeJS / browsers, written in Typescript.\n\nThis can be used to generate grids of days, representing a calendar month, by passing in any `Date` in the desired month.\n\n## Installation\n\nInstall by running `npm install date-matrix --save`.\n\n## Usage\n\nImport `createDateMatrix` to create a date matrix object:\n\n```typescript\nimport { DateMatrix, createDateMatrix } from \"date-matrix\";\n\nconst dm: DateMatrix = createDateMatrix(new Date(\"2021-04-30\"));\n// {\n//     weekdays: [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"],\n//     weeks: [\n//         // ...\n//     ]\n// }\n```\n\n`weeks` is an array of weeks (rows), representing Monday-Sunday in a calendar grid (or Sunday-Saturday when using `{ firstDay: \"sunday\" }`).\n\nEach day **object** looks like the following:\n\n```javascript\n{\n    day: 30,\n    date: Date(),\n    type: \"current\"\n}\n```\n\nTo just render the days as-is, you could use a helper function like so:\n\n```typescript\nfunction weeksToNumbers(weeks) {\n    return weeks.map(week =\u003e week.map(item =\u003e item.day));\n}\n\nconst dm: DateMatrix = createDateMatrix(new Date(\"2021-04-30\"));\nconst matrix = weeksToNumbers(dm.weeks);\n// [\n//     [29, 30, 31, 1, 2, 3, 4],\n//     [5, 6, 7, 8, 9, 10, 11],\n//     [12, 13, 14, 15, 16, 17, 18],\n//     [19, 20, 21, 22, 23, 24, 25],\n//     [26, 27, 28, 29, 30, 1, 2]\n// ]\n```\n\n### createDateMatrix\n\nThe function takes two parameters:\n\n```typescript\ncreateDateMatrix(date: Date, options?: DateMatrixOptions) =\u003e DateMatrix\n```\n\n| Parameter         | Type              | Required  | Description                           |\n|-------------------|-------------------|-----------|---------------------------------------|\n| `date`            | `Date`            | Yes       | The target date, with which to generate the date matrix from (using its month). |\n| `options`         | `DateMatrixOptions`| No       | Options for the matrix creation.      |\n\nWith the `options` parameter supporting the following properties:\n\n| Property          | Default           | Description                                       |\n|-------------------|-------------------|---------------------------------------------------|\n| `firstDay`        | `monday`          | The first day of the week, either `monday` or `sunday`. |\n| `locale`          | _undefined_       | The locale to use for date handling, eg. `en-GB`. |\n| `weekdayFormat`   | `short`           | The Date function weekday format, either `short` or `long`. |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperry-mitchell%2Fdate-matrix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperry-mitchell%2Fdate-matrix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperry-mitchell%2Fdate-matrix/lists"}