{"id":26499164,"url":"https://github.com/aguilarpgc/timelapse","last_synced_at":"2025-03-20T14:52:21.653Z","repository":{"id":63901442,"uuid":"150327343","full_name":"aguilarpgc/TimeLapse","owner":"aguilarpgc","description":"Simple Date \u0026 Int extension with time lapse description format","archived":false,"fork":false,"pushed_at":"2021-06-30T16:32:10.000Z","size":23241,"stargazers_count":5,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-01T16:17:49.868Z","etag":null,"topics":["date","formatting","swift","swift-package-manager","time"],"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/aguilarpgc.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}},"created_at":"2018-09-25T20:46:39.000Z","updated_at":"2021-07-08T10:45:26.000Z","dependencies_parsed_at":"2023-01-14T12:45:40.168Z","dependency_job_id":null,"html_url":"https://github.com/aguilarpgc/TimeLapse","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aguilarpgc%2FTimeLapse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aguilarpgc%2FTimeLapse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aguilarpgc%2FTimeLapse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aguilarpgc%2FTimeLapse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aguilarpgc","download_url":"https://codeload.github.com/aguilarpgc/TimeLapse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244637063,"owners_count":20485445,"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","formatting","swift","swift-package-manager","time"],"created_at":"2025-03-20T14:52:21.028Z","updated_at":"2025-03-20T14:52:21.646Z","avatar_url":"https://github.com/aguilarpgc.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TimeLapse\n\n[![Version](https://img.shields.io/github/tag/aguilarpgc/TimeLapse.svg?colorB=blue\u0026label=release\u0026style=flat)](https://github.com/aguilarpgc/TimeLapse/releases)\n[![Swift](https://img.shields.io/badge/swift-5.0-orange.svg?style=flat)](https://developer.apple.com/swift/)\n[![Platform](https://img.shields.io/badge/platform-ios%20%7C%20macos%20%7C%20tvos%20%7C%20watchos-lightgrey.svg)](https://developer.apple.com/swift/)\n[![License](https://img.shields.io/badge/license-MIT-71787A.svg)](https://tldrlegal.com/license/mit-license)\n\n`Date` extension that compares another `Date` with current time, converts it in seconds and returns a formatted time lapse description.\n\n## Installation\n\n### Swift Package Manager\n\n```\ndependencies: [\n    .package(url: \"https://github.com/aguilarpgc/TimeLapse.git\", from: \"0.5.0\")\n]\n```\n\n## Example\n\n![Alt Text](https://github.com/aguilarpgc/TimeLapse/blob/master/Resources/demo.gif?raw=true)\n\n## Usage\n\n### Default\n\n``` Swift\nimport Foundation\nimport TimeLapse\n\nlet currentDate  = Date()\nlet fakePastDate = Calendar.current.date(byAdding: .second, value: -600, to: currentDate)! // 10 minutes ago\n\nlet timeLapse = fakePastDate.elapsedTime(until: currentDate)\n\nprint(timeLapse) // 10min\n```\n\n#### Date\n\n``` Swift\nlet dateFormatter = DateFormatter()\ndateFormatter.dateFormat = \"dd/MM/yyyy HH:mm:ss\"\n\nlet fakeCurrentDate = dateFormatter.date(from: \"24/12/2018 23:59:59\")!\n\n// some test dates\nlet date0  = dateFormatter.date(from: \"24/12/2018 23:59:58\")!\nlet date1  = dateFormatter.date(from: \"24/12/2018 23:59:09\")!\nlet date2  = dateFormatter.date(from: \"24/12/2018 23:52:59\")!\nlet date3  = dateFormatter.date(from: \"24/12/2018 18:59:59\")!\nlet date4  = dateFormatter.date(from: \"23/12/2018 23:59:59\")!\nlet date5  = dateFormatter.date(from: \"09/12/2018 23:59:59\")!\nlet date6  = dateFormatter.date(from: \"24/11/2018 23:59:59\")!\nlet date7  = dateFormatter.date(from: \"24/12/2016 23:59:59\")!\n\ndate0.elapsedTime(until: fakeCurrentDate)\ndate1.elapsedTime(until: fakeCurrentDate)\ndate2.elapsedTime(until: fakeCurrentDate)\ndate3.elapsedTime(until: fakeCurrentDate)\ndate4.elapsedTime(until: fakeCurrentDate)\ndate5.elapsedTime(until: fakeCurrentDate)\ndate6.elapsedTime(until: fakeCurrentDate)\ndate7.elapsedTime(until: fakeCurrentDate)\n```\n\n* Just Now : **just now**\n* Seconds  : **50s**\n* Minutes  : **7min**\n* Hours    : **5h**\n* Days     : **1d**\n* Weeks    : **2w**\n* Months   : **1mo**\n* Years    : **2y**\n\n#### Int (Seconds)\n\n``` Swift\n2.shortTimeLapse()\n10.shortTimeLapse()\n1800.shortTimeLapse()\n43200.shortTimeLapse()\n172_800.shortTimeLapse()\n604_800.shortTimeLapse()\n15_552_000.shortTimeLapse()\n31_536_000.shortTimeLapse()\n```\n* Just Now : **just now**\n* Seconds  : **10s**\n* Minutes  : **30min**\n* Hours    : **12h**\n* Days     : **2d**\n* Weeks    : **1w**\n* Months   : **6mo**\n* Years    : **1y**\n\n### Customize Format\n\nConforms to the protocol `TimeLapseFormat` and assign custom format to `TimeLapse.format`\n\n#### Example\n\n``` Swift\nstruct CustomTimeLapseFormat: TimeLapseFormat {\n\n    var now    : String = \"now\"\n    var second : String = \"sec\"\n    var minute : String = \"m\"\n    var hour   : String = \"hour\"\n    var day    : String = \"d\"\n    var week   : String = \"w\"\n    var month  : String = \"mon\"\n    var year   : String = \"y\"\n\n}\n```\n##### Assign for usage:\n\n``` Swift\nTimeLapse.format = CustomTimeLapseFormat()\n```\n\n##### Result:\n\n``` Swift\n0.shortTimeLapse()\n10.shortTimeLapse()\n1800.shortTimeLapse()\n7200.shortTimeLapse()\n604_799.shortTimeLapse()\n2_591_999.shortTimeLapse()\n31_535_999.shortTimeLapse()\n630_720_000.shortTimeLapse()\n```\n\n* Just Now : **now**\n* Seconds  : **10sec**\n* Minutes  : **30m**\n* Hours    : **2hour**\n* Days     : **6d**\n* Weeks    : **4w**\n* Months   : **12mon**\n* Years    : **20y**\n\n##### Restore to default format\n\n``` Swift\nTimeLapse.enableDefaultFormat()\n```\n\n# License\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the MIT License.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faguilarpgc%2Ftimelapse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faguilarpgc%2Ftimelapse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faguilarpgc%2Ftimelapse/lists"}