{"id":13533964,"url":"https://github.com/date-fns/date-fns-upgrade-codemod","last_synced_at":"2025-04-15T14:31:39.026Z","repository":{"id":44091032,"uuid":"200801654","full_name":"date-fns/date-fns-upgrade-codemod","owner":"date-fns","description":"Code mods for upgrading date-fns versions","archived":false,"fork":false,"pushed_at":"2023-01-04T06:24:52.000Z","size":1389,"stargazers_count":11,"open_issues_count":14,"forks_count":4,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-30T01:38:10.521Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/date-fns.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-06T07:40:51.000Z","updated_at":"2021-07-08T11:41:29.000Z","dependencies_parsed_at":"2023-02-02T01:16:27.627Z","dependency_job_id":null,"html_url":"https://github.com/date-fns/date-fns-upgrade-codemod","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/date-fns%2Fdate-fns-upgrade-codemod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/date-fns%2Fdate-fns-upgrade-codemod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/date-fns%2Fdate-fns-upgrade-codemod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/date-fns%2Fdate-fns-upgrade-codemod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/date-fns","download_url":"https://codeload.github.com/date-fns/date-fns-upgrade-codemod/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223676010,"owners_count":17184162,"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-08-01T07:01:24.840Z","updated_at":"2024-11-08T11:26:37.959Z","avatar_url":"https://github.com/date-fns.png","language":"JavaScript","funding_links":[],"categories":["Misc"],"sub_categories":["ant-design"],"readme":"## date-fns-codemod\n\n### Usage\n\n`npx @date-fns/upgrade-codemod \u003cpath\u003e [...options]`\n  * `path` files or directory to transform\n  * `--dry` option for a dry-run\n  * `--print` option to print the output for comparison\n\n#### Example\n\n```sh\nnpx @date-fns/upgrade-codemod src/\n```\n\n### Codemods applied\n\n*N.B.* At the moment this codemod applies fixes ONLY for first 3 points of\n2.0 date-fns [CHANGELOG](https://github.com/date-fns/date-fns/blob/master/CHANGELOG.md#changed)\\\nYou'll have to take care of all the other breaking changes.\n\nCodemod imports required tools from `@date-fns/upgrade`\n(you will have to add it as dependency in your project if required) and wraps\n`date-fns` function call arguments accordingly.\n\n```diff\n+import { legacyParse, legacyParseMap, convertTokens } from '@date-fns/upgrade/v2'\n\n const dateIs = '2019-07-01'\n\n const someToken = 'MM-DD';\n-const format = importedFormat('2019-07-01', someToken)\n-const closestIndex = closestToIndex(new Date(2015, 8, 6), [\n-  new Date(2015, 0, 1),\n-  new Date(2016, 0, 1),\n-  new Date(2017, 0, 1)\n-])\n-const addSecondsPlease = addSeconds(dateIs, 999)\n-const isoDay = getThatDay(new Date())\n+const format = importedFormat(\n+  legacyParse('2019-07-01'),\n+  convertTokens(someToken)\n+)\n+const closestIndex = closestToIndex(\n+  legacyParse(new Date(2015, 8, 6)),\n+  legacyParseMap([\n+    new Date(2015, 0, 1),\n+    new Date(2016, 0, 1),\n+    new Date(2017, 0, 1)\n+  ])\n+)\n+const addSecondsPlease = addSeconds(legacyParse(dateIs), 999)\n+const isoDay = getThatDay(legacyParse(new Date()))\n```\n\nCodemod also changes import locations\n\n```diff\n import * as importedFormat from 'date-fns/format'\n-import closestToIndex from 'date-fns/closest_to_index'\n-import addSeconds from 'date-fns/add_seconds'\n-import getThatDay from 'date-fns/get_iso_day'\n+import closestToIndex from 'date-fns/closestToIndex'\n+import addSeconds from 'date-fns/addSeconds'\n+import getThatDay from 'date-fns/getISODay'\n```\n\n### PRs welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdate-fns%2Fdate-fns-upgrade-codemod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdate-fns%2Fdate-fns-upgrade-codemod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdate-fns%2Fdate-fns-upgrade-codemod/lists"}