{"id":19032753,"url":"https://github.com/joutvhu/date-parser","last_synced_at":"2025-02-21T20:28:37.728Z","repository":{"id":48784394,"uuid":"377933827","full_name":"joutvhu/date-parser","owner":"joutvhu","description":"Utility to parse String to Date according to a target class, and the pattern strings. And format Date to String based on a pattern string.","archived":false,"fork":false,"pushed_at":"2023-07-28T07:04:14.000Z","size":344,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-02T04:28:43.626Z","etag":null,"topics":["date","parser","time","type-class"],"latest_commit_sha":null,"homepage":"","language":"Java","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/joutvhu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2021-06-17T18:59:40.000Z","updated_at":"2023-07-28T07:04:18.000Z","dependencies_parsed_at":"2024-11-08T21:41:24.074Z","dependency_job_id":null,"html_url":"https://github.com/joutvhu/date-parser","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joutvhu%2Fdate-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joutvhu%2Fdate-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joutvhu%2Fdate-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joutvhu%2Fdate-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joutvhu","download_url":"https://codeload.github.com/joutvhu/date-parser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240082916,"owners_count":19745318,"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","parser","time","type-class"],"created_at":"2024-11-08T21:30:57.850Z","updated_at":"2025-02-21T20:28:37.709Z","avatar_url":"https://github.com/joutvhu.png","language":"Java","readme":"# Date Parser\n\n[![GitHub](https://img.shields.io/github/license/joutvhu/date-parser)](https://github.com/joutvhu/date-parser/blob/main/LICENSE)\n[![codecov](https://codecov.io/gh/joutvhu/date-parser/branch/main/graph/badge.svg?token=2OJDWTPPGW)](https://codecov.io/gh/joutvhu/date-parser)\n\nThis is a Date Utility with two purposes:\n- Parse String to Date according to a target class, and the pattern strings.\n- Format Date to String based on a pattern string.\n\n## Installation\n\n- If you are using Gradle just add the following dependency to your `build.gradle`.\n\n```groovy\nimplementation \"com.github.joutvhu:date-parser:1.0.0\"\n```\n\n- Or add the following dependency to your `pom.xml` if you are using Maven.\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.joutvhu\u003c/groupId\u003e\n    \u003cartifactId\u003edate-parser\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Using\n\n### DateFormatter\n\n- `withConvertor(Class\u003cT\u003e typeOfConvertor, Convertor\u003cT\u003e convertor)` or `withConvertor(Convertor\u003cT\u003e convertor)` used to add a custom convertor to the `DateFormatter`.\n  - Use these methods to add a [`Convertor`](./src/main/java/com/joutvhu/date/parser/convertor/Convertor.java).\n\n- `withLocale(Locale defaultLocale)` used to set default `java.util.Locale`, if this value is null the default value is `Locale.getDefault()`.\n\n- `withZone(TimeZone defaultZone)` used to set default `java.util.TimeZone`, if this value is null the default value is `TimeZone.getDefault()`.\n\n- `withWeekFields(WeekFields defaultWeekFields)` used to set default `java.time.temporal.WeekFields`, if this value is null the default value is `WeekFields.of(locale)`.\n\n- `withStrategyFactory(StrategyFactory strategyFactory)` used to override [`StrategyFactory`](./src/main/java/com/joutvhu/date/parser/strategy/StrategyFactory.java).\n  - Use this method to add, update or delete a [`Strategy`](./src/main/java/com/joutvhu/date/parser/strategy/Strategy.java).\n\n- `parse(Class\u003cT\u003e type, String value, String... patterns)` used to parse string to date.\n  - `type` is the type of target object you want to get.\n  - `value` is the input string you want to convert to the target object.\n  - `patterns` are the possible formats of the input string.\n\n- `format(T object, String pattern)` used to format an object to a target string.\n  - `object` is the input object you want to convert to string.\n  - `pattern` is the format of the target string.\n\n### DateParser\n\n- `DateParser.formatter()` will be return a new [`DateFormatter`](#DateFormatter).\n\n- `DateParser.parse(Class\u003cT\u003e type, String value, String... patterns)` is equivalent to `DateParser.formatter().parse(Class\u003cT\u003e type, String value, String... patterns)`.\n\n- `DateParser.format(T object, String pattern)` is equivalent to `DateParser.formatter().format(T object, String pattern)`.\n\n## Example\n\n- Parse Date\n```java\nDate date = DateParser.formatter().parse(Date.class, \"2021-06-27 21:52:25.408\", \"yyyy-MM-dd HH:mm:ss.SSS\");\n\nLocalDateTime localDateTime = DateParser.parse(LocalDateTime.class, \"2021-06-27 21:52:25.408\", \"yyyy-MM-dd HH:mm:ss.SSS\");\n\nInstant instant = DateParser.parse(Instant.class, \"2021-06-28T02:22:48.780101Z\", \"yyyy-MM-dd'T'HH:mm:ss.SSSZ\");\n\nDayOfWeek dayOfWeek = DateParser.formatter().withWeekFields(WeekFields.ISO).parse(DayOfWeek.class, \"Sun\", \"E\");\n```\n\n- Format Date\n```java\nString date = DateParser.format(new Date(), \"MMM dd, yyyy hh:mm:ss a\");\n\nString instant = DateParser.format(Instant.now(), \"yyyy-MM-dd'T'HH:mm:ss.SSSX\");\n\nString yearMonth = DateParser.format(YearMonth.of(2021, Month.DECEMBER), \"Mo yyyy\");\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoutvhu%2Fdate-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoutvhu%2Fdate-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoutvhu%2Fdate-parser/lists"}