{"id":13496782,"url":"https://github.com/dankinsoid/VDDate","last_synced_at":"2025-03-28T19:31:05.573Z","repository":{"id":187833121,"uuid":"677662828","full_name":"dankinsoid/VDDate","owner":"dankinsoid","description":"Robust set of extensions for the Date struct","archived":false,"fork":false,"pushed_at":"2024-09-03T08:35:22.000Z","size":84,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-02T21:45:38.948Z","etag":null,"topics":["date","datecomponents","foundation","swift"],"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/dankinsoid.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":"2023-08-12T08:00:47.000Z","updated_at":"2024-09-03T08:35:26.000Z","dependencies_parsed_at":"2023-09-05T10:15:14.694Z","dependency_job_id":null,"html_url":"https://github.com/dankinsoid/VDDate","commit_stats":null,"previous_names":["dankinsoid/vddate"],"tags_count":12,"template":false,"template_full_name":"dankinsoid/iOSLibraryTemplate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dankinsoid%2FVDDate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dankinsoid%2FVDDate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dankinsoid%2FVDDate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dankinsoid%2FVDDate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dankinsoid","download_url":"https://codeload.github.com/dankinsoid/VDDate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246088428,"owners_count":20721682,"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":["date","datecomponents","foundation","swift"],"created_at":"2024-07-31T19:01:59.604Z","updated_at":"2025-03-28T19:31:05.232Z","avatar_url":"https://github.com/dankinsoid.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"# VDDate 📆\n\nVDDate is a Swift library that offers a robust set of extensions for the Date struct, enhancing its capabilities and making date manipulation in Swift more intuitive and powerful.\n\n## Features\n### Date\n- Convenience `Date.init`s with components parameters year, month, day etc.\n- Convenience `Date.init`s from string with format.\n- Static computed property `Date.now` that can be mocked if needed. It's recommended to use `Date.now` instead of `Date()`.\n- Helper vars: `iToday`, `isTomorrow`, `isYesterday`, `iso8601`.\n- var `components`, var for each component: `day`, `month`, `year` etc, mutating subscript with `Calendar.Component`.\n- `start(of: Calendar.Component) -\u003e Date`.\n- `end(of: Calendar.Component) -\u003e Date`.\n- `matches(DateComponents) -\u003e Bool`.\n- `isInSame(Calendar.Component) -\u003e Bool`.\n- `isCurrent(Calendar.Component) -\u003e Bool`\n- `isEqual(to: Date, toGranularity: Calendar.Component) -\u003e Bool`.\n- `number(of: Calendar.Component, from: Date) -\u003e Int`\n- `numbers(of components: Set\u003cCalendar.Component\u003e, from: Date) -\u003e DateComponents`\n- `components(_ components: Set\u003cCalendar.Component\u003e, from: Date) -\u003e DateComponents`\n- `range(of: Calendar.Component, in: Calendar.Component) -\u003e Range\u003cInt\u003e` - range of component, for example `range(of: .day, in: .month)` returns smth like `1..\u003c32`.\n- `interval(byAdding: DateComponents) -\u003e DateInterval`\n- `interval(of: Calendar.Component, in: Calendar.Component) -\u003e DateInterval`\n- `number(of: Calendar.Component) -\u003e Int`\n- `number(of: Calendar.Component, in: Calendar.Component) -\u003e Int`\n- `DateFormat` struct with predefined format components.\n- `string(DateFormat) -\u003e String` Note: Deprecated since iOS 15.0 in favor of `formatted(FormatStyle)`.\n- `string(date: DateFormatter.Style, time: DateFormatter.Style) -\u003e String` Note: Deprecated since iOS 15.0 in favor of `formatted(FormatStyle)`.\n- `string(format: RelativeDateFormat\u003cDateFormat\u003e)` - method for converting formatting date relative to current (or any other) date. Note: Deprecated since iOS 15.0 in favor of `formatted(RelativeDateFormatStyle)`\n- `formatted(RelativeDateFormatStyle)`\n- `name(of: Calendar.Component) -\u003e String`\n- `ordinality(of: Calendar.Component, in: Calendar.Component) -\u003e Int?` and convenience methods for each component like `day(in: Calendar.Component)`.\n- Minus operator for date returns TimeInterval.\n- `adding(DateComponents) -\u003e Date`\n- `adding(Int, Calendar.Component) -\u003e Date`\n- `setting(DateComponents) -\u003e Date`\n- `setting(Int, Calendar.Component) -\u003e Date`\n- `compare(with: Date, toGranularity: Calendar.Component) -\u003e ComparasionResult`\n- `nextWeekend(direction: Calendar.SearchDirection) -\u003e DateInterval?`\n- `next(Calendar.Component, direction: Calendar.SearchDirection) -\u003e Date`\n- `nearest(DateComponents) -\u003e Date?`\n- `rounded(Calendar.Component, by: Int) -\u003e Date` date rounded by some component, useful when you deal with regular time intervals.\n#### Note\nAll methods accept a `Calendar` parameter and, in some cases, `TimeZone` or `Locale`.\\\nI've introduced static variables: `Calendar.default`, `TimeZone.default`, and `Locale.default`.\\\nThese variables serve as the default values for each respective method. You can modify each `default` variable either globally or specifically for a given method.\n\nOverload for `Calendar` parameter globally:\n```swift\nCalendar.bootstrap(default: Calendar(identifier: .gregorian))\n```\nUse `Calendar` parameter for a specific method:\n```swift\ndate.start(of: .day, calendar: Calendar(identifier: .gregorian))\n```\nTip: You can use `TaskLocal` to set the default value for a specific task and it's subtasks.\n```swift\nextension Calendar {\n  @TaskLocal\n  static var local: Calendar = .autoupdatingCurrent\n}\n\nCalendar.bootstrap(default: .local)\n\nCalendar.$local.withValue(Calendar(identifier: .gregorian)) {\n  print(Date.now.start(of: .day))\n}\n```\n\n### TimeInterval\n- `DatesCollection` struct and function `each(Int, Calendar.Component) -\u003e DatesCollection`.\n### DateComponents\n- Arithmetic operators: +, - between `DateComponents`, +, -, /, * between `DateComponents` and `Int`, +, - between `DateComponents` and `Date`.\n- Convenience static methods for each component like `.day(3)`.\n- Extensions on `BinaryInteger` like `2.days`, so now it possible to write `date + 2.days`.\n- `DateComponents` now is expressible by dictionary literal like `[.day: 2, .month: 1]`\n- mutating subscript  with `Calendar.Components`.\n- `rawValue: [Calendar.Component: Int]` - dictionary with components.\n\n## Installation\n\n1. [Swift Package Manager](https://github.com/apple/swift-package-manager)\n\nCreate a `Package.swift` file.\n```swift\n// swift-tools-version:5.7\nimport PackageDescription\n\nlet package = Package(\n  name: \"SomeProject\",\n  dependencies: [\n    .package(url: \"https://github.com/dankinsoid/VDDate.git\", from: \"0.14.0\")\n  ],\n  targets: [\n    .target(name: \"SomeProject\", dependencies: [\"VDDate\"])\n  ]\n)\n```\n```ruby\n$ swift build\n```\n\n## Author\n\ndankinsoid, voidilov@gmail.com\n\n## License\n\nVDDate is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdankinsoid%2FVDDate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdankinsoid%2FVDDate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdankinsoid%2FVDDate/lists"}