{"id":1053,"url":"https://github.com/melvitax/DateHelper","last_synced_at":"2025-08-06T13:32:13.884Z","repository":{"id":18742239,"uuid":"21954071","full_name":"melvitax/DateHelper","owner":"melvitax","description":"A Swift Date extension helper","archived":false,"fork":false,"pushed_at":"2024-03-26T08:26:47.000Z","size":699,"stargazers_count":1508,"open_issues_count":10,"forks_count":239,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-07-28T07:06:58.245Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","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/melvitax.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":"2014-07-17T19:05:22.000Z","updated_at":"2025-07-01T07:03:28.000Z","dependencies_parsed_at":"2024-01-02T20:56:52.098Z","dependency_job_id":"323611f8-9b96-457b-9a5c-c807e4c1c69a","html_url":"https://github.com/melvitax/DateHelper","commit_stats":{"total_commits":150,"total_committers":40,"mean_commits":3.75,"dds":0.6133333333333333,"last_synced_commit":"76d0840daab7288fc99b04a4c23d504f0394e083"},"previous_names":[],"tags_count":53,"template":false,"template_full_name":null,"purl":"pkg:github/melvitax/DateHelper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melvitax%2FDateHelper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melvitax%2FDateHelper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melvitax%2FDateHelper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melvitax%2FDateHelper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/melvitax","download_url":"https://codeload.github.com/melvitax/DateHelper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/melvitax%2FDateHelper/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268607328,"owners_count":24277542,"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","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-01-05T20:15:37.922Z","updated_at":"2025-08-06T13:32:13.531Z","avatar_url":"https://github.com/melvitax.png","language":"Swift","readme":"# DateHelper 5.0.1\n\n[![License](https://img.shields.io/badge/License-MIT-lightgrey)](https://github.com/melvitax/DateHelper/blob/master/LICENSE)\n[![Platform](https://img.shields.io/badge/Platform-iOS%20%7C%20watchOS%20%7C%20tvOS%20%7C%20macOS-lightgrey)](https://github.com/melvitax/DateHelper)\n[![Carthage Compatible](https://img.shields.io/badge/Carthage-Compatible-green)](https://github.com/Carthage/Carthage)\n[![Swift Package Manager Compatible](https://img.shields.io/badge/Swift%20Package%20Manager-Compatible-green)](https://swift.org/package-manager/)\n\n![Sample Project Screenshot](https://raw.githubusercontent.com/melvitax/DateHelper/master/logo.png \"Date Helper\")\n\nA high performant Swift Date Extension for creating, comparing, or modifying dates. \n\n\n## Capabilities\n- **Date from String**\n\t- Using date detection i.e. `\"Tomorrow at 5:30 PM\"`\n\t- With predefined format: i.e. `.isoDateTime` \n\t- With custom format: i.e. `\"dd MMM yyyy HH:mm:ss\"`\n- **String from Date**\n\t- With predefined format: i.e. `.rss`\n\t- With custom format: i.e. `\"\"MMM d, yyyy\"\"`\n    - With combined date and time style: i.e. `.medium`\n    - With individual date and time style: i.e. `.medium, .short`\n- **Modify Date**\n    - Offset date component: i.e. `.offset(.second, value: 110)`\n    - Adjust date component: i.e. `.adjust(hour: 12, minute: 0, second: 0)`\n    - Adjust date to a predefined time: i.e. `.adjust(for: .startOfDay)`\n- **Compare Date**\n    - Compare against relative date in predefined format: i.e. `.isToday, .isThisWeek`\n    - Compare againnst target date: i.e. `firstDate.compare(.isSameMonth(as: secondDate))`\n- **Time Since**\n    - Time since target date in component: i.e. `Date().since(secondDate, in: .second)`\n- **Extras**\n    - Extract date and time components: i.e. `.hour, .minute, .day`\n    - Conveniance methods: i.e. `numberOfDaysInMonth(), firstDayOfWeek(), .lastDayOfWeek()` \n\n## Date From String\nProvides initializers to create a Date from a String\n\n\n### Detect a Date from natural language in a String\n\n```swift\nDate(detectFromString: \"Tomorrow at 5:30 PM\")\n```\nUses NSDataDetector to detect a date from natural language in a string. It works similar to how Apple Mail detects dates. This initializer is not as efficient as **fromString:format:** and should not be used in collections or lists.\n\n\n### Date from a string with predefined format\n\n```swift\n Date(fromString: \"2009\", format: .isoYear)\n Date(fromString: \"2009-08\", format: .isoYearMonth)\n Date(fromString: \"2009-08-11\", format: .isoDate)\n Date(fromString: \"2009-08-11T06:00:00-07:00\", format: .isoDateTime)\n Date(fromString: \"2009-08-11T06:00:00.000-07:00\", format: .isoDateTimeFull)\n Date(fromString: \"/Date(1260123281843)/\", format: .dotNet)\n Date(fromString: \"Fri, 09 Sep 2011 15:26:08 +0200\", format: .rss)\n Date(fromString: \"09 Sep 2011 15:26:08 +0200\", format: .altRSS)\n Date(fromString: \"Wed, 01 03 2017 06:43:19 -0500\", format: .httpHeader)\n```\nHighly performant, cached and thread safe. Can optionally receive timeZone, locale or  isLenient flag.\n\n### Date from a string with custom format\n\n```swift\n Date(fromString: \"16 July 1972 6:12:00\", format: .custom(\"dd MMM yyyy HH:mm:ss\"))\n```\nHighly performant, cached and thread safe. Can optionally receive timeZone, locale or  isLenient flag.\n\n## String From Date\nProvides three ways to convert a Date object to a String\n\n\n### Convert Date to String using predefined format\n\n```swift\nDate().toString(format: .isoYear)\n\"2017\"\nDate().toString(format: .isoYearMonth)\n\"2017-03\"\nDate().toString(format: .isoDate)\n\"2017-03-01\"\nDate().toString(format: .isoDateTime)\n\"2017-03-01T06:43:19-05:00\"\nDate().toString(format: .isoDateTimeFull)\n\"2017-03-01T06:43:19.000-05:00\"\nDate().toString(format: .dotNet)\n\"/Date(-51488368599000.000000)/\"\nDate().toString(format: .rss)\n\"Wed, 1 Mar 2017 06:43:19 -0500\"\nDate().toString(format: .altRSS)\n\"1 Mar 2017 06:43:19 -0500\"\nDate().toString(format: .httpHeader)\n\"Wed, 01 03 2017 06:43:19 -0500\"\n```\nHighly performant, cached and thread safe. Can optionally receive timeZone and locale.\n\n### Convert Date to String using custom format\n\n```swift\nDate().toString(format: .custom(\"MMM d, yyyy\"))\n\"Mar 1, 2017\"\nDate().toString(format: .custom(\"h:mm a\"))\n\"6:43 AM\"\nDate().toString(format: .custom(\"MMM d\"))\n\"Wed Mar 1\"\n```\nHighly performant, cached and thread safe. Can optionally receive timeZone and locale.\n\n### Convert Date to String using predefined combined date and time styles\n```swift\nDate().toString(style: .short) \n\"3/1/17, 6:43 AM\"\nDate().toString(style: .medium)\n\"Mar 1, 2017 at 6:43:19 AM\"\nDate().toString(style: .long)\n\"March 1, 2017 at 6:43:19 AM EST\"\nDate().toString(style: .full)\n\"Wednesday, March 1, 2017 at 6:43:19 AM Eastern Standard Time\"\nDate().toString(style: .ordinalDay)\n\"1st\"\nDate().toString(style: .weekday)\n\"Wednesday\"\nDate().toString(style: .shortWeekday)\n\"Wed\"\nDate().toString(style: .veryShortWeekday)\n\"W\"\nDate().toString(style: .month)\n\"April\"\nDate().toString(style: .shortMonth)\n\"Apr\"\nDate().toString(style: .veryShortMonth)\n\"A\"\n```\n\n### Convert Date to String using predefined individual date and time styles\n\n```swift \nDate().toString(dateStyle: .none, timeStyle: .short)\n\"6:43 AM\"\nDate().toString(dateStyle: .short, timeStyle: .none)\n\"3/1/17\"\nDate().toString(dateStyle: .short, timeStyle: .short)\n\"3/1/17, 6:43 AM\"\nDate().toString(dateStyle: .medium, timeStyle: .medium)\n\"Mar 1, 2017 at 6:43:19 AM\"\nDate().toString(dateStyle: .long, timeStyle: .long)\n\"March 1, 2017 at 6:43:19 AM EST\"\nDate().toString(dateStyle: .full, timeStyle: .full)\n\"Wednesday, March 1, 2017 at 6:43:19 AM Eastern Standard Time\"\n```\n\n## Modifying dates\nProvides functions for adjusting or shifting dates\n\n### Offset components\n\n```swift \nDate().offset(.second, value: 10)\n\"18:14:41\" -\u003e \"18:14:51\"\nDate().offset(.minute, value: 10)\n\"18:14:41\" -\u003e \"18:24:41\"\nDate().offset(.hour, value: 2)\n\"18:14:41\" -\u003e \"20:14:41\"\nDate().offset(.day, value: 1)\n\"2009-12-06\" -\u003e \"2009-12-07\"\nDate().offset(.weekday, value: 2)\n\"2009-12-06\" -\u003e \"2009-16-06\"\nDate().offset(.weekdayOrdinal, value: 1)\n\"2009-12-06\" -\u003e \"2009-12-20\"\nDate().offset(.week, value: -2)\n\"2009-12-06\" -\u003e  \"2009-11-22\"\nDate().offset(.month, value: 2)\n\"2009-12-06\" -\u003e \"2010-02-06\"\nDate().offset(.year, value: -2)\n\"2009-12-06\" -\u003e \"2007-12-06\"\n```\n\n### Adjust components\nModifies date with the specified date component  \n\n```swift \nDate().adjust(hour: 1, minute: 10, second: 30, day: 15, month: 1)\n\"2009-12-06 18:14:41\" -\u003e \"2009-01-15 06:10:30\"\nDate().adjust(minute: 59)\n\"2009-12-06 18:14:41\" -\u003e \"2009-12-06 18:59:30\"\n```\n\n### Adjust date\nModifies date with predefined times like endOfDay, startOfDay startOfWeek etc.\n\n```swift \nDate().adjust(for: .startOfDay)\n\"2009-12-06 18:14:41\" -\u003e \"2009-12-06 00:00:00\"\nDate().adjust(for: .endOfDay)\n\"2009-12-06 18:14:41\" -\u003e \"2009-12-06 23-59-59\"\nDate().adjust(for: .startOfWeek)\n\"2009-12-08 18:14:41\" -\u003e \"2009-12-06 18:14:41\"\nDate().adjust(for: .endOfWeek)\n\"2009-12-06 18:14:41\" -\u003e \"2009-12-12 18:14:41\"\nDate().adjust(for: .startOfMonth)\n\"2009-12-06 18:14:41\" -\u003e \"2009-12-01 18:14:41\"\nDate().adjust(for: .endOfMonth)\n\"2009-12-06 18:14:41\" -\u003e \"2009-12-31 18:14:41\"\nDate().adjust(for: .tomorrow)\n\"2009-12-06 18:14:41\" -\u003e \"tomorrow at 18:14:41\"\nDate().adjust(for: .yesterday)\n\"2009-12-06 18:14:41\" -\u003e \"yesterday at 18:14:41\"\nDate().adjust(for: .nearestMinute(minute:30))\n\"2009-12-07 18-14-00\" -\u003e \"2009-12-07 18-00-00\"\n\"2009-12-07 18-40-00\" -\u003e \"2009-12-07 18-30-00\"\n\"2009-12-07 18-50-00\" -\u003e \"2009-12-07 19-00-00\"\nDate().adjust(for: .nearestHour(hour:2)) \n\"2009-12-07 18-00-00\" -\u003e \"2009-12-08 00-00-00\"\n\"2009-12-07 07-00-00\" -\u003e \"2009-12-07 12-00-00\"\n\"2009-12-07 03-00-00\" -\u003e \"2009-12-07 00-00-00\"\nDate().adjust(for: .startOfYear)\n\"2009-12-06 18:14:41\" -\u003e \"2009-01-01 00-00-00\"\nDate().adjust(for: .endOfYear)\n\"2009-12-06 18:14:41\" -\u003e \"2009-12-31 23-59-59\"\n```\n\n## Compare Dates\nCompares dates using predefined times like today, tomorrow, this year, next year etc. Returns true if it matches.\n\n### Compare against relative date\n```swift\nDate().compare(.isToday)\nDate().compare(.isTomorrow)\nDate().compare(.isYesterday)\nDate().compare(.isThisWeek)\nDate().compare(.isNextWeek)\nDate().compare(.isLastWeek)\nDate().compare(.isThisYear)\nDate().compare(.isNextYear)\nDate().compare(.isLastYear)\nDate().compare(.isInTheFuture)\nDate().compare(.isInThePast)\nDate().compare(.isWeekend)\n\"2021-12-15\" != weekend\n\"2021-12-18\" == weekend\n```\n\n### Compare against another date\n```swift\nfirstDate.compare(.isSameDay(as: secondDate))\n\"2022-01-08\" != \"2022-01-07\"\n\"2022-01-06\" != \"2022-01-07\"\n\"2022-01-07\" == \"2022-01-07\"\nfirstDate.compare(.isSameWeek(as: secondDate))\n\"2022-01-14\" != \"2022-01-07\"\n\"2021-12-31\" != \"2022-01-07\"\n\"2022-01-07\" == \"2022-01-07\"\nfirstDate.compare(.isSameMonth(as: secondDate))\n\"2022-02-07\" != \"2022-01-07\"\n\"2021-12-07\" != \"2022-01-07\"\n\"2022-01-07\" == \"2022-01-07\"\nfirstDate.compare(.isSameYear(as: secondDate))\n\"2023-01-07\" != \"2022-01-07\"\n\"2021-01-07\" != \"2022-01-07\"\n\"2022-01-07\" == \"2022-01-07\"\nfirstDate.compare(.isEarlier(than: secondDate))\n\"2022-01-07 19:26:53\" != \"2022-01-07 19:25:53\"\n\"2022-01-07 19:24:53\" == \"2022-01-07 19:25:53\"\nfirstDate.compare(.isLater(than: secondDate))\n\"2022-01-07 19:28:49\" == \"2022-01-07 19:27:49\"\n\"2022-01-07 19:26:49\" != \"2022-01-07 19:27:49\"\n```\n\n## Time since...  \nReturns a number in the specified unit of measure since the secondary date.  \n\n```swift\nDate().since(secondDate, in: .second)\n\"2009-12-06 06-14-11\" since \"2009-12-06 06-13-41\" in .second == 30 \nDate().since(secondDate, in: .minute)\n\"2009-12-06 06-14-11\" since \"2009-12-06 04-14-11\" in .minute == 120 \nDate().since(secondDate, in: .hour)\n\"2009-12-06 06-14-11\" since \"2009-12-06 04-14-11\" in .hour == 2 \nDate().since(secondDate, in: .day)\n\"2009-12-06\" since \"2009-12-05\" in .day == 1 \nDate().since(secondDate, in: .week)\n\"2009-12-06\" since \"2009-11-29\" in .week == 1\n\"2009-12-06\" since \"2009-12-13\" in .week == -1\nDate().since(secondDate, in: .weekdayOrdinal)\n\"2009-12-06\" since \"2009-11-22\" in .weekdayOrdinal == 2\nDate().since(secondDate, in: .month)\n\"2009-12-06\" since \"2009-11-06\" in .month == 2\nDate().since(secondDate, in: .year)  \n\"2009-12-06\" since \"2008-12-06\" in .year == 1\n```\n\n## Miscellaneous\n\n### Extracting components from a date\n\n```swift\nDate().component(.second)\n\"2009-12-06 18:14:11\" .second == \"11\"\nDate().component(.minute)\n\"2009-12-06 18:14:11\" .minute == \"14\"\nDate().component(.hour)\n\"2009-12-06 18:14:11\" .hour == \"18\"\nDate().component(.day)\n\"2009-12-06 18:14:11\" .day == \"6\"\nDate().component(.weekday)\n\"2009-12-06 18:14:11\" .weekday == \"1\"\nDate().component(.weekdayOrdinal)\n\"2009-12-06 18:14:11\" .weekdayOrdinal == \"1\"\nDate().component(.month)\n\"2009-12-06 18:14:11\" .month == \"12\"\nDate().component(.year)\n\"2009-12-06 18:14:11\" .year == \"2009\"\n```\n\n### Conveneience methods \n\n```swift\nDate().numberOfDaysInMonth()\n\"2021-12-17\" numberOfDaysInMonth() == 31\nDate().firstDayOfWeek()\n\"2021-12-17\" firstDayOfWeek() == 12\nDate().lastDayOfWeek()\n\"2021-12-17\" lastDayOfWeek() == 19\n```\n\n### Custom start day of the week\n\n```swift\nvar calendar = Calendar(identifier: .gregorian)\ncalendar.firstWeekday = 2 // sets the week to start on Monday\nDate().dateFor(.startOfWeek, calendar: calendar)\n```\n\n## Custom Component guide\n\n**Unicode Date Field Symbol Guide**\n\n| Format  | Description | Example |\n| ------------- | ------------- | ------------- |\n| \"y\" | 1 digit min year | 1, 42, 2017 |\n| \"yy\" | 2 digit year | 01, 42, 17 |\n| \"yyy\" | 3 digit min year | 001, 042, 2017 |\n| \"yyyy\" | 4 digit min year | 0001, 0042, 2017 |\n| \"M\" | 1 digit min month | 7, 12 |\n| \"MM\" | 2 digit month  | 07, 12 |\n| \"MMM\" | 3 letter month abbr. | Jul, Dec |\n| \"MMMM\" | Full month | July, December |\n| \"MMMMM\" | 1 letter month abbr. | J, D |\n| \"d\" | 1 digit min day | 4, 25 |\n| \"dd\" | 2 digit day | 04, 25 |\n| \"E\", \"EE\", \"EEE\" | 3 letter day name abbr. | Wed, Thu |\n| \"EEEE\" | full day name | Wednesday, Thursday |\n| \"EEEEE\" | 1 letter day name abbr. | W, T |\n| \"EEEEEE\" | 2 letter day name abbr. | We, Th |\n| \"a\" | Period of day | AM, PM |\n| \"h\" | AM/PM 1 digit min hour | 5, 7 |\n| \"hh\" | AM/PM 2 digit hour | 05, 07 |\n| \"H\" | 24 hr 1 digit min hour | 17, 7 |\n| \"HH\" | 24 hr 2 digit hour | 17, 07 |\n| \"m\" | 1 digit min minute | 1, 40 |\n| \"mm\" | 2 digit minute | 01, 40 |\n| \"s\" | 1 digit min second | 1, 40 |\n| \"ss\" | 2 digit second | 01, 40 |\n| \"S\" | 10th's place of fractional second | 123ms -\u003e 1, 7ms -\u003e 0 |\n| \"SS\" | 10th's \u0026 100th's place of fractional second | 123ms -\u003e 12, 7ms -\u003e 00 |\n| \"SSS\" | 10th's \u0026 100th's \u0026 1,000's place of fractional second | 123ms -\u003e 123, 7ms -\u003e 007 |\n\n## Requirements\n\nLanguage: Swift 5.0\nSupports: iOS, tvOS, watchOS, macOS\n\n\n## Installation\n\n**Swift Package Manager** https://github.com/melvitax/DateHelper.git  \n**Carthage** github \"melvitax/DateHelper\"  \n**Manually**  Include DateHelper.swift in your project  \n\n\n## Author\n\nMelvin Rivera\n\n## License\n\nDateHelper is available under the MIT license. See the LICENSE file for more info.\n","funding_links":[],"categories":["Date \u0026 Time","Libs","Minor","Swift","Date [🔝](#readme)","etc"],"sub_categories":["Getting Started","Date","Other free courses","Linter"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmelvitax%2FDateHelper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmelvitax%2FDateHelper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmelvitax%2FDateHelper/lists"}