{"action":"created","issue":{"url":"https://api.github.com/repos/pureconfig/pureconfig/issues/359","repository_url":"https://api.github.com/repos/pureconfig/pureconfig","labels_url":"https://api.github.com/repos/pureconfig/pureconfig/issues/359/labels{/name}","comments_url":"https://api.github.com/repos/pureconfig/pureconfig/issues/359/comments","events_url":"https://api.github.com/repos/pureconfig/pureconfig/issues/359/events","html_url":"https://github.com/pureconfig/pureconfig/issues/359","id":297835923,"number":359,"title":"Support the HOCON 1.3.2 Period Format for java.time.Period","user":{"login":"ches","id":13277,"avatar_url":"https://avatars3.githubusercontent.com/u/13277?v=4","gravatar_id":"","url":"https://api.github.com/users/ches","html_url":"https://github.com/ches","followers_url":"https://api.github.com/users/ches/followers","following_url":"https://api.github.com/users/ches/following{/other_user}","gists_url":"https://api.github.com/users/ches/gists{/gist_id}","starred_url":"https://api.github.com/users/ches/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ches/subscriptions","organizations_url":"https://api.github.com/users/ches/orgs","repos_url":"https://api.github.com/users/ches/repos","events_url":"https://api.github.com/users/ches/events{/privacy}","received_events_url":"https://api.github.com/users/ches/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-16T16:08:06Z","updated_at":"2018-02-16T19:43:49Z","closed_at":null,"author_association":"NONE","body":"I hoped this would Just Work™, but it appears pureconfig's `Period` support predates that of Typesafe Config 1.3.2 (lightbend/config#478) and doesn't know about the new HOCON unit syntax yet:\r\n\r\n```scala\r\ncase class Conf(period: java.time.Period)\r\n\r\nval config = ConfigFactory.parseString(\"\"\"{ period = 5 years }\"\"\")\r\n\r\nconfig.getPeriod(\"period\") // => java.time.Period = P5Y\r\n\r\npureconfig.loadConfigOrThrow[Conf](config) // BOOM\r\n```\r\n\r\npureconfig does handle `ConfigFactory.parseString(\"\"\"{ period: P5Y }\"\"\")`, but Typesafe `getPeriod` does not, and it's not quite as nice for humans.\r\n\r\nIt's unfortunate that Typesafe Config doesn't seem to expose its parsers, so users would need to copy-and-paste a big hunk of its package-private code to define an overriding `ConfigReader[Period]` instance supporting the syntax.\r\n\r\nI thought I wouldn't be the last to expect this to work, thus opening this issue. If I have the chance, I'll look more closely at the existing `Duration` support and try to come up with a suitable PR. Should pureconfig try HOCON format parsing and fall back to ISO-8601 `Period.parse` transparently? This doesn't quite fit the mold of existing configurable converters.\r\n\r\nThank you for the library, I'm enjoying the type richness and boilerplate reduction!"},"comment":{"url":"https://api.github.com/repos/pureconfig/pureconfig/issues/comments/366338926","html_url":"https://github.com/pureconfig/pureconfig/issues/359#issuecomment-366338926","issue_url":"https://api.github.com/repos/pureconfig/pureconfig/issues/359","id":366338926,"user":{"login":"ruippeixotog","id":613493,"avatar_url":"https://avatars3.githubusercontent.com/u/613493?v=4","gravatar_id":"","url":"https://api.github.com/users/ruippeixotog","html_url":"https://github.com/ruippeixotog","followers_url":"https://api.github.com/users/ruippeixotog/followers","following_url":"https://api.github.com/users/ruippeixotog/following{/other_user}","gists_url":"https://api.github.com/users/ruippeixotog/gists{/gist_id}","starred_url":"https://api.github.com/users/ruippeixotog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ruippeixotog/subscriptions","organizations_url":"https://api.github.com/users/ruippeixotog/orgs","repos_url":"https://api.github.com/users/ruippeixotog/repos","events_url":"https://api.github.com/users/ruippeixotog/events{/privacy}","received_events_url":"https://api.github.com/users/ruippeixotog/received_events","type":"User","site_admin":false},"created_at":"2018-02-16T19:43:49Z","updated_at":"2018-02-16T19:43:49Z","author_association":"OWNER","body":"Hi @ches, thanks for submitting the issue! I was not aware that Typesafe config supported `Period` natively.\r\n\r\n> Should pureconfig try HOCON format parsing and fall back to ISO-8601 Period.parse transparently? This doesn't quite fit the mold of existing configurable converters.\r\n\r\nI'm fine with this approach. `Period` [isn't a configurable converter](https://github.com/pureconfig/pureconfig/blob/master/core/src/main/scala/pureconfig/BasicReaders.scala#L92) as it doesn't depend on a time zone and we already have `Duration` ([declaration](https://github.com/pureconfig/pureconfig/blob/master/core/src/main/scala/pureconfig/BasicReaders.scala#L108), [implementation](https://github.com/pureconfig/pureconfig/blob/master/core/src/main/scala/pureconfig/DurationConvert.scala)) in the same situation. Since those two formats do not overlap, we can safely try parsing one and falling back to the other.\r\n"}}
{"actor":{"display_login":"ruippeixotog"}}