{"action":"created","comment":{"url":"https://api.github.com/repos/bethard/timenorm/pulls/comments/59125148","id":59125148,"diff_hunk":"@@ -294,12 +307,129 @@ case class IntervalSubIntervalIntersection(interval: Interval, subInterval: Repe\n   val end = ???\n }\n \n-trait RepeatingInterval extends TimeExpression\n-case class UnitRepeatingInterval(unit: TemporalUnit, modifier: Modifier) extends RepeatingInterval\n-case class FieldRepeatingInterval(field: TemporalField, value: Long, modifier: Modifier) extends RepeatingInterval\n-case class NumberedRepeatingInterval(repeatingInterval: RepeatingInterval, number: Number) extends RepeatingInterval\n-case class RepeatingIntervalUnion(repeatingIntervals: Set[RepeatingInterval]) extends RepeatingInterval\n-case class RepeatingIntervalIntersection(repeatingIntervals: Set[RepeatingInterval]) extends RepeatingInterval\n-case class IntervalAsRepeatingInterval(interval: Interval) extends RepeatingInterval\n+trait RepeatingInterval extends TimeExpression {\n+  def preceding(interval: Interval): Iterator[Interval]\n+  def following(interval: Interval): Iterator[Interval]\n+\n+  private[formal] def truncate(ldt: LocalDateTime, tUnit: TemporalUnit): LocalDateTime = {\n+    tUnit match {\n+      case ChronoUnit.CENTURIES => LocalDateTime.of(ldt.getYear/100*100,1,1,0,0)\n+      case ChronoUnit.DECADES => LocalDateTime.of(ldt.getYear/10*10,1,1,0,0)\n+      case ChronoUnit.YEARS => ldt.withDayOfYear(1).truncatedTo(ChronoUnit.DAYS)\n+      case ChronoUnit.MONTHS => ldt.withDayOfMonth(1).truncatedTo(ChronoUnit.DAYS)\n+      case ChronoUnit.WEEKS =>\n+        ldt.withDayOfYear(ldt.getDayOfYear-ldt.getDayOfWeek.getValue).truncatedTo(ChronoUnit.DAYS)\n+      case _ => ldt.truncatedTo(tUnit)\n+    }\n+  }\n+}\n+\n+case class UnitRepeatingInterval(unit: TemporalUnit, modifier: Modifier) extends RepeatingInterval {\n+  override def preceding(interval: Interval): Iterator[Interval] = {\n+    var end = truncate( interval.start, unit ).plus(1,unit)\n+    var start = end.minus(1, unit)\n+\n+    Iterator.continually {\n+      start = start.minus(1, unit)\n+      end = end.minus(1, unit)\n+      SimpleInterval(start, end)\n+    }\n+  }\n+\n+  override def following(interval: Interval): Iterator[Interval] = {\n+    var start = truncate(interval.end, unit)\n+    var end = start.plus(1,unit)\n+\n+    Iterator.continually {\n+      start = start.plus(1, unit)\n+      end = end.plus(1, unit)\n+      SimpleInterval(start, end)\n+    }\n+  }\n+}\n+\n+\n+case class FieldRepeatingInterval(field: TemporalField, value: Long, modifier: Modifier) extends RepeatingInterval {\n+  if ( !field.range.isValidValue(value))\n+    throw new IllegalArgumentException\n+\n+  override def preceding(interval: Interval): Iterator[Interval] = {\n+    var start = truncate(interval.start.`with`(field,value), field.getBaseUnit)\n+\n+    if (start.isBefore(interval.start))\n+      start = start.plus(1,field.getRangeUnit)\n+\n+    var end = start.plus(1,field.getBaseUnit)","path":"src/main/scala/info/bethard/timenorm/formal/Types.scala","position":120,"original_position":120,"commit_id":"924b0d17975bbdbea046b8ff232c6bda28a3b8b9","original_commit_id":"924b0d17975bbdbea046b8ff232c6bda28a3b8b9","user":{"login":"bethard","id":1118599,"avatar_url":"https://avatars.githubusercontent.com/u/1118599?v=3","gravatar_id":"","url":"https://api.github.com/users/bethard","html_url":"https://github.com/bethard","followers_url":"https://api.github.com/users/bethard/followers","following_url":"https://api.github.com/users/bethard/following{/other_user}","gists_url":"https://api.github.com/users/bethard/gists{/gist_id}","starred_url":"https://api.github.com/users/bethard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bethard/subscriptions","organizations_url":"https://api.github.com/users/bethard/orgs","repos_url":"https://api.github.com/users/bethard/repos","events_url":"https://api.github.com/users/bethard/events{/privacy}","received_events_url":"https://api.github.com/users/bethard/received_events","type":"User","site_admin":false},"body":"It seems like this statement is not needed, and you can just declare \"end\" as a \"val\" below?","created_at":"2016-04-10T01:39:58Z","updated_at":"2016-04-10T01:39:58Z","html_url":"https://github.com/bethard/timenorm/pull/14#discussion_r59125148","pull_request_url":"https://api.github.com/repos/bethard/timenorm/pulls/14","_links":{"self":{"href":"https://api.github.com/repos/bethard/timenorm/pulls/comments/59125148"},"html":{"href":"https://github.com/bethard/timenorm/pull/14#discussion_r59125148"},"pull_request":{"href":"https://api.github.com/repos/bethard/timenorm/pulls/14"}}},"pull_request":{"url":"https://api.github.com/repos/bethard/timenorm/pulls/14","id":65892934,"html_url":"https://github.com/bethard/timenorm/pull/14","diff_url":"https://github.com/bethard/timenorm/pull/14.diff","patch_url":"https://github.com/bethard/timenorm/pull/14.patch","issue_url":"https://api.github.com/repos/bethard/timenorm/issues/14","number":14,"state":"open","locked":false,"title":"RepeatingInterval implementations","user":{"login":"awmarkley","id":9114130,"avatar_url":"https://avatars.githubusercontent.com/u/9114130?v=3","gravatar_id":"","url":"https://api.github.com/users/awmarkley","html_url":"https://github.com/awmarkley","followers_url":"https://api.github.com/users/awmarkley/followers","following_url":"https://api.github.com/users/awmarkley/following{/other_user}","gists_url":"https://api.github.com/users/awmarkley/gists{/gist_id}","starred_url":"https://api.github.com/users/awmarkley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/awmarkley/subscriptions","organizations_url":"https://api.github.com/users/awmarkley/orgs","repos_url":"https://api.github.com/users/awmarkley/repos","events_url":"https://api.github.com/users/awmarkley/events{/privacy}","received_events_url":"https://api.github.com/users/awmarkley/received_events","type":"User","site_admin":false},"body":"- Implemented FieldRepeatingInterval\r\n- Implemented UnitRepeatingInterval\r\n- Added SimpleInterval\r\n- Tests added for Between\r\n- Tests added for FieldRepeatingInterval and UnitRepeatingInterval","created_at":"2016-04-09T21:23:13Z","updated_at":"2016-04-10T01:39:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9f0bffbe6c1a4b1d67b7d4f79daf3639a0b63740","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bethard/timenorm/pulls/14/commits","review_comments_url":"https://api.github.com/repos/bethard/timenorm/pulls/14/comments","review_comment_url":"https://api.github.com/repos/bethard/timenorm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bethard/timenorm/issues/14/comments","statuses_url":"https://api.github.com/repos/bethard/timenorm/statuses/924b0d17975bbdbea046b8ff232c6bda28a3b8b9","head":{"label":"awmarkley:repeating-interval","ref":"repeating-interval","sha":"924b0d17975bbdbea046b8ff232c6bda28a3b8b9","user":{"login":"awmarkley","id":9114130,"avatar_url":"https://avatars.githubusercontent.com/u/9114130?v=3","gravatar_id":"","url":"https://api.github.com/users/awmarkley","html_url":"https://github.com/awmarkley","followers_url":"https://api.github.com/users/awmarkley/followers","following_url":"https://api.github.com/users/awmarkley/following{/other_user}","gists_url":"https://api.github.com/users/awmarkley/gists{/gist_id}","starred_url":"https://api.github.com/users/awmarkley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/awmarkley/subscriptions","organizations_url":"https://api.github.com/users/awmarkley/orgs","repos_url":"https://api.github.com/users/awmarkley/repos","events_url":"https://api.github.com/users/awmarkley/events{/privacy}","received_events_url":"https://api.github.com/users/awmarkley/received_events","type":"User","site_admin":false},"repo":{"id":50381535,"name":"timenorm","full_name":"awmarkley/timenorm","owner":{"login":"awmarkley","id":9114130,"avatar_url":"https://avatars.githubusercontent.com/u/9114130?v=3","gravatar_id":"","url":"https://api.github.com/users/awmarkley","html_url":"https://github.com/awmarkley","followers_url":"https://api.github.com/users/awmarkley/followers","following_url":"https://api.github.com/users/awmarkley/following{/other_user}","gists_url":"https://api.github.com/users/awmarkley/gists{/gist_id}","starred_url":"https://api.github.com/users/awmarkley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/awmarkley/subscriptions","organizations_url":"https://api.github.com/users/awmarkley/orgs","repos_url":"https://api.github.com/users/awmarkley/repos","events_url":"https://api.github.com/users/awmarkley/events{/privacy}","received_events_url":"https://api.github.com/users/awmarkley/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/awmarkley/timenorm","description":"","fork":true,"url":"https://api.github.com/repos/awmarkley/timenorm","forks_url":"https://api.github.com/repos/awmarkley/timenorm/forks","keys_url":"https://api.github.com/repos/awmarkley/timenorm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/awmarkley/timenorm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/awmarkley/timenorm/teams","hooks_url":"https://api.github.com/repos/awmarkley/timenorm/hooks","issue_events_url":"https://api.github.com/repos/awmarkley/timenorm/issues/events{/number}","events_url":"https://api.github.com/repos/awmarkley/timenorm/events","assignees_url":"https://api.github.com/repos/awmarkley/timenorm/assignees{/user}","branches_url":"https://api.github.com/repos/awmarkley/timenorm/branches{/branch}","tags_url":"https://api.github.com/repos/awmarkley/timenorm/tags","blobs_url":"https://api.github.com/repos/awmarkley/timenorm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/awmarkley/timenorm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/awmarkley/timenorm/git/refs{/sha}","trees_url":"https://api.github.com/repos/awmarkley/timenorm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/awmarkley/timenorm/statuses/{sha}","languages_url":"https://api.github.com/repos/awmarkley/timenorm/languages","stargazers_url":"https://api.github.com/repos/awmarkley/timenorm/stargazers","contributors_url":"https://api.github.com/repos/awmarkley/timenorm/contributors","subscribers_url":"https://api.github.com/repos/awmarkley/timenorm/subscribers","subscription_url":"https://api.github.com/repos/awmarkley/timenorm/subscription","commits_url":"https://api.github.com/repos/awmarkley/timenorm/commits{/sha}","git_commits_url":"https://api.github.com/repos/awmarkley/timenorm/git/commits{/sha}","comments_url":"https://api.github.com/repos/awmarkley/timenorm/comments{/number}","issue_comment_url":"https://api.github.com/repos/awmarkley/timenorm/issues/comments{/number}","contents_url":"https://api.github.com/repos/awmarkley/timenorm/contents/{+path}","compare_url":"https://api.github.com/repos/awmarkley/timenorm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/awmarkley/timenorm/merges","archive_url":"https://api.github.com/repos/awmarkley/timenorm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/awmarkley/timenorm/downloads","issues_url":"https://api.github.com/repos/awmarkley/timenorm/issues{/number}","pulls_url":"https://api.github.com/repos/awmarkley/timenorm/pulls{/number}","milestones_url":"https://api.github.com/repos/awmarkley/timenorm/milestones{/number}","notifications_url":"https://api.github.com/repos/awmarkley/timenorm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/awmarkley/timenorm/labels{/name}","releases_url":"https://api.github.com/repos/awmarkley/timenorm/releases{/id}","deployments_url":"https://api.github.com/repos/awmarkley/timenorm/deployments","created_at":"2016-01-25T21:17:07Z","updated_at":"2016-01-25T21:17:08Z","pushed_at":"2016-04-10T01:10:08Z","git_url":"git://github.com/awmarkley/timenorm.git","ssh_url":"git@github.com:awmarkley/timenorm.git","clone_url":"https://github.com/awmarkley/timenorm.git","svn_url":"https://github.com/awmarkley/timenorm","homepage":null,"size":386,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"bethard:master","ref":"master","sha":"ef8b5d86ab057e1bdf3173e38ed8548aecb33ba8","user":{"login":"bethard","id":1118599,"avatar_url":"https://avatars.githubusercontent.com/u/1118599?v=3","gravatar_id":"","url":"https://api.github.com/users/bethard","html_url":"https://github.com/bethard","followers_url":"https://api.github.com/users/bethard/followers","following_url":"https://api.github.com/users/bethard/following{/other_user}","gists_url":"https://api.github.com/users/bethard/gists{/gist_id}","starred_url":"https://api.github.com/users/bethard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bethard/subscriptions","organizations_url":"https://api.github.com/users/bethard/orgs","repos_url":"https://api.github.com/users/bethard/repos","events_url":"https://api.github.com/users/bethard/events{/privacy}","received_events_url":"https://api.github.com/users/bethard/received_events","type":"User","site_admin":false},"repo":{"id":7830673,"name":"timenorm","full_name":"bethard/timenorm","owner":{"login":"bethard","id":1118599,"avatar_url":"https://avatars.githubusercontent.com/u/1118599?v=3","gravatar_id":"","url":"https://api.github.com/users/bethard","html_url":"https://github.com/bethard","followers_url":"https://api.github.com/users/bethard/followers","following_url":"https://api.github.com/users/bethard/following{/other_user}","gists_url":"https://api.github.com/users/bethard/gists{/gist_id}","starred_url":"https://api.github.com/users/bethard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bethard/subscriptions","organizations_url":"https://api.github.com/users/bethard/orgs","repos_url":"https://api.github.com/users/bethard/repos","events_url":"https://api.github.com/users/bethard/events{/privacy}","received_events_url":"https://api.github.com/users/bethard/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bethard/timenorm","description":"","fork":false,"url":"https://api.github.com/repos/bethard/timenorm","forks_url":"https://api.github.com/repos/bethard/timenorm/forks","keys_url":"https://api.github.com/repos/bethard/timenorm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bethard/timenorm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bethard/timenorm/teams","hooks_url":"https://api.github.com/repos/bethard/timenorm/hooks","issue_events_url":"https://api.github.com/repos/bethard/timenorm/issues/events{/number}","events_url":"https://api.github.com/repos/bethard/timenorm/events","assignees_url":"https://api.github.com/repos/bethard/timenorm/assignees{/user}","branches_url":"https://api.github.com/repos/bethard/timenorm/branches{/branch}","tags_url":"https://api.github.com/repos/bethard/timenorm/tags","blobs_url":"https://api.github.com/repos/bethard/timenorm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bethard/timenorm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bethard/timenorm/git/refs{/sha}","trees_url":"https://api.github.com/repos/bethard/timenorm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bethard/timenorm/statuses/{sha}","languages_url":"https://api.github.com/repos/bethard/timenorm/languages","stargazers_url":"https://api.github.com/repos/bethard/timenorm/stargazers","contributors_url":"https://api.github.com/repos/bethard/timenorm/contributors","subscribers_url":"https://api.github.com/repos/bethard/timenorm/subscribers","subscription_url":"https://api.github.com/repos/bethard/timenorm/subscription","commits_url":"https://api.github.com/repos/bethard/timenorm/commits{/sha}","git_commits_url":"https://api.github.com/repos/bethard/timenorm/git/commits{/sha}","comments_url":"https://api.github.com/repos/bethard/timenorm/comments{/number}","issue_comment_url":"https://api.github.com/repos/bethard/timenorm/issues/comments{/number}","contents_url":"https://api.github.com/repos/bethard/timenorm/contents/{+path}","compare_url":"https://api.github.com/repos/bethard/timenorm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bethard/timenorm/merges","archive_url":"https://api.github.com/repos/bethard/timenorm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bethard/timenorm/downloads","issues_url":"https://api.github.com/repos/bethard/timenorm/issues{/number}","pulls_url":"https://api.github.com/repos/bethard/timenorm/pulls{/number}","milestones_url":"https://api.github.com/repos/bethard/timenorm/milestones{/number}","notifications_url":"https://api.github.com/repos/bethard/timenorm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bethard/timenorm/labels{/name}","releases_url":"https://api.github.com/repos/bethard/timenorm/releases{/id}","deployments_url":"https://api.github.com/repos/bethard/timenorm/deployments","created_at":"2013-01-25T23:41:16Z","updated_at":"2016-02-04T18:49:11Z","pushed_at":"2016-04-10T01:10:09Z","git_url":"git://github.com/bethard/timenorm.git","ssh_url":"git@github.com:bethard/timenorm.git","clone_url":"https://github.com/bethard/timenorm.git","svn_url":"https://github.com/bethard/timenorm","homepage":null,"size":616,"stargazers_count":5,"watchers_count":5,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":3,"forks":4,"open_issues":3,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bethard/timenorm/pulls/14"},"html":{"href":"https://github.com/bethard/timenorm/pull/14"},"issue":{"href":"https://api.github.com/repos/bethard/timenorm/issues/14"},"comments":{"href":"https://api.github.com/repos/bethard/timenorm/issues/14/comments"},"review_comments":{"href":"https://api.github.com/repos/bethard/timenorm/pulls/14/comments"},"review_comment":{"href":"https://api.github.com/repos/bethard/timenorm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bethard/timenorm/pulls/14/commits"},"statuses":{"href":"https://api.github.com/repos/bethard/timenorm/statuses/924b0d17975bbdbea046b8ff232c6bda28a3b8b9"}}}}