Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial revamp of ranges/intervals #127

Merged
merged 318 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
318 commits
Select commit Hold shift + click to select a range
81cd55f
Try to fix Android emulator
erikc5000 Oct 28, 2019
c233419
Travis fixes for Android emulator, try 2
erikc5000 Oct 28, 2019
8a6fdd9
Travis fixes for Android emulator, try 3
erikc5000 Oct 28, 2019
6b16b02
Travis fixes for Android emulator, try 4
erikc5000 Oct 28, 2019
bd3b935
Travis fixes for Android emulator, try 5
erikc5000 Oct 28, 2019
345b66e
Minor tweaks, mainly to docs
erikc5000 Oct 28, 2019
3c3bfc0
Minor tweaks to ZonedDateTime constructors
erikc5000 Oct 28, 2019
a1ec19d
Travis fixes for Android emulator, try 6
erikc5000 Oct 28, 2019
9c03704
Build fix
erikc5000 Oct 28, 2019
d999fbf
Travis fixes for Android emulator, try 7
erikc5000 Oct 28, 2019
871519e
Travis fixes for Android emulator, try 8
erikc5000 Oct 28, 2019
1b33782
Travis fixes for Android emulator, try 9
erikc5000 Oct 28, 2019
5938130
Bump KotlinPoet to 1.4.1
erikc5000 Oct 28, 2019
eabef4e
Added contains operators to check if a smaller calendrical unit is wi…
erikc5000 Oct 28, 2019
6da48a1
UtcOffset documentation clean up -- and made toComponents() inline
erikc5000 Oct 29, 2019
dae12fa
Fixed forced duration unit lengthening being unnecessarily applied on…
erikc5000 Oct 29, 2019
a3a7cc3
Bump Gradle to 5.6.4
erikc5000 Nov 2, 2019
a834925
Make buildIsoString() inline
erikc5000 Nov 2, 2019
8a8b336
Cleaned up a lot of edge cases around time zones, particularly when d…
erikc5000 Nov 3, 2019
62c22c9
Make withInclusiveEnd() methods internal
erikc5000 Nov 5, 2019
0b688fa
Bump AGP to 3.6.0-beta02
erikc5000 Nov 5, 2019
5f3a1be
Added support for open start and end in DateRange
erikc5000 Nov 6, 2019
c20c89e
Cleaned up packaged parsers and removed some of the ordinal ones
erikc5000 Nov 6, 2019
05e9f4c
Cleaned up lint, style errors, and dead code
erikc5000 Nov 6, 2019
e0c53d4
Removed invoke() construction from Time (#1)
erikc5000 Nov 6, 2019
1e8f4b3
Added conversions to InstantInterval from other ranges, harmonized na…
erikc5000 Nov 8, 2019
e5aadce
Update to AGP 3.6.0-beta03
erikc5000 Nov 8, 2019
1501c8f
Documentation updates
erikc5000 Nov 10, 2019
cb27b4f
More documentation updates.
erikc5000 Nov 10, 2019
7058dfd
More documentation updates
erikc5000 Nov 10, 2019
42ccc12
Documentation tweaks
erikc5000 Nov 10, 2019
6dc30c0
Documentation and naming updates
erikc5000 Nov 10, 2019
92d14e0
Converted Instant to a non-inline class, cleaned up the API, and expa…
erikc5000 Nov 10, 2019
0377675
Fixed broken iOS tests
erikc5000 Nov 10, 2019
d59cac1
Cleaned up ranges/intervals and expanded documentation/tests
erikc5000 Nov 11, 2019
820a20e
Expanded documentation
erikc5000 Nov 11, 2019
925e967
Removed invoke() constructors from DayOfWeek and Month (#1)
erikc5000 Nov 12, 2019
7388637
Expanded documentation
erikc5000 Nov 12, 2019
b6def1a
Converted YearMonth from inline class to regular class (#3)
erikc5000 Nov 13, 2019
5893d8e
Clean ups to DayOfWeek and Month (support Long in add/subtract and ve…
erikc5000 Nov 13, 2019
da6e86e
Expanded documentation and renamed/reworked properties/methods in eff…
erikc5000 Nov 13, 2019
cf4af38
Fix mismatched parameter name
erikc5000 Nov 14, 2019
aa6fd07
Bump AGP to 3.6.0-beta04
erikc5000 Nov 15, 2019
6ca9864
Revamped code generation to include day-based units and eliminate the…
erikc5000 Nov 15, 2019
3ec0612
Coverted a few properties to functions to be more consistent with the…
erikc5000 Nov 16, 2019
020ba55
Fixed iOS dependencies not getting published correctly
erikc5000 Nov 18, 2019
c7c6ee7
Minor cleanup in iOS time zone rules
erikc5000 Nov 18, 2019
72cdbc0
Updated README
erikc5000 Nov 18, 2019
a499b67
Bump Gradle to 6.0.1
erikc5000 Nov 19, 2019
2d10b19
Bump Kotlin to 1.3.60
erikc5000 Nov 19, 2019
6b8c3ed
Bump XCode version to 11
erikc5000 Nov 19, 2019
929da85
Add Kotlin dependency info to the README
erikc5000 Nov 19, 2019
c0ff1d2
Try creating the iOS simulator in travis.yml
erikc5000 Nov 19, 2019
184b5e1
Update .travis.yml
erikc5000 Nov 19, 2019
bca6ec0
Update .travis.yml
erikc5000 Nov 19, 2019
24f19ee
Update .travis.yml
erikc5000 Nov 19, 2019
41b0606
Try fixing Travis simulator setup again
erikc5000 Nov 19, 2019
dfe3d70
Try fixing Travis simulator setup again...
erikc5000 Nov 19, 2019
d0148dd
Removed unused import
erikc5000 Nov 19, 2019
1305fee
Add support for tvOS and watchOS
erikc5000 Nov 19, 2019
ded9765
Back out tvOS and watchOS support since they aren't in Stately right now
erikc5000 Nov 20, 2019
4bc674c
Update README.md
erikc5000 Nov 20, 2019
03cd8d6
Merge pull request #13 from erikc5000/gradle-6.0.1
erikc5000 Nov 20, 2019
e36ae98
Merge remote-tracking branch 'origin/master'
erikc5000 Nov 20, 2019
79d23a7
Further refactoring of TemporalUnitGenerator
erikc5000 Nov 20, 2019
45c1b6b
Make overflow safe operations the default and unchecked internal only
erikc5000 Nov 23, 2019
4a580df
Fixed timesExact() behavior when multiplying Long.MIN_VALUE by -1 on …
erikc5000 Nov 23, 2019
e829503
Code cleanup
erikc5000 Nov 23, 2019
6210c1a
Addressed TODO items with unchecked operations
erikc5000 Nov 23, 2019
34ee158
Add more overflow tests on Period
erikc5000 Nov 23, 2019
ba62e42
Add ability to do scalar * duration or period
erikc5000 Nov 23, 2019
1e6d002
Merge pull request #15 from erikc5000/duration-unit-rework
erikc5000 Nov 23, 2019
8fe75d1
OffsetTime no longer implements Comparable, making it consistent with…
erikc5000 Nov 24, 2019
483b6df
Documentation improvements
erikc5000 Nov 24, 2019
2305586
More documentation improvements
erikc5000 Nov 24, 2019
2ec400c
Updated README -- still a work in progress
erikc5000 Nov 26, 2019
1a60c93
More README updates
erikc5000 Nov 27, 2019
e7ae82e
Update README.md
erikc5000 Nov 27, 2019
fd9ce65
Package re-organization (#16)
erikc5000 Nov 27, 2019
c392145
Update Kotlin to 1.3.61
erikc5000 Nov 27, 2019
6f49144
Make JVM TimeZoneRulesProvider compatible with Android's java.time su…
erikc5000 Nov 27, 2019
c776ef9
More README tweaks
erikc5000 Nov 27, 2019
1c30931
Fix README grammar
erikc5000 Nov 28, 2019
6783713
Add more examples to README
erikc5000 Nov 28, 2019
7e4801e
Make isZero property a function for consistency
erikc5000 Nov 28, 2019
83f8dd9
Throw an exception when creating a range/interval with an inclusive e…
erikc5000 Nov 29, 2019
e7c8d8c
Prepare version 0.1.0
erikc5000 Nov 29, 2019
4e2ece0
Prepare next release
erikc5000 Nov 29, 2019
6e78567
Add jacoco test coverage task for common code
erikc5000 Dec 2, 2019
63bae18
Fixed issue with ZonedDateTime dayOfYear constructor
erikc5000 Dec 6, 2019
d7563cf
Add test coverage for DateTimeInterval
erikc5000 Dec 6, 2019
ff3e0f8
Fix DateTimeInterval equality
erikc5000 Dec 6, 2019
e089e46
Add module with parcelers for all date-time primitives and ranges
erikc5000 Dec 6, 2019
e2ee87d
Bump AGP to 3.6.0-beta05
erikc5000 Dec 6, 2019
14e02f7
Revert Travis changes that didn't work
erikc5000 Dec 6, 2019
4ef3d8a
Revert Travis changes that didn't work
erikc5000 Dec 6, 2019
f5aa4db
Try fixing Android emulator
erikc5000 Dec 6, 2019
81d1dfe
Revert Travis back...
erikc5000 Dec 6, 2019
4c2db0e
Merge pull request #17 from erikc5000/parcelize-extensions
erikc5000 Dec 8, 2019
df6fd47
Try fixing Android emulator on Travis
erikc5000 Dec 8, 2019
677b7ba
Update .travis.yml
erikc5000 Dec 8, 2019
bee2382
Update .travis.yml
erikc5000 Dec 8, 2019
9a6cd9b
Update .travis.yml
erikc5000 Dec 8, 2019
a2af532
Update .travis.yml
erikc5000 Dec 8, 2019
899d887
Update .travis.yml
erikc5000 Dec 9, 2019
41717b4
Update .travis.yml
erikc5000 Dec 9, 2019
379de42
Update .travis.yml
erikc5000 Dec 9, 2019
c45ab4e
Update .travis.yml
erikc5000 Dec 9, 2019
f9640cc
Update .travis.yml
erikc5000 Dec 9, 2019
79892e1
Update .travis.yml
erikc5000 Dec 9, 2019
b643c97
Update .travis.yml
erikc5000 Dec 9, 2019
8574258
Update .travis.yml
erikc5000 Dec 9, 2019
e4caa0a
Update .travis.yml
erikc5000 Dec 9, 2019
20e440b
Update .travis.yml
erikc5000 Dec 9, 2019
12a734c
Update .travis.yml
erikc5000 Dec 9, 2019
2cb9c0b
Update .travis.yml
erikc5000 Dec 9, 2019
53a6d59
Add android-wait-for-emulator script for Travis
erikc5000 Dec 9, 2019
a8db35d
Update .travis.yml
erikc5000 Dec 9, 2019
896cb81
Try working around Android emulator issue again
erikc5000 Dec 10, 2019
6dfd164
Fix system clock test
erikc5000 Dec 11, 2019
17d8c9b
Reset time zone rules provider before each test
erikc5000 Dec 11, 2019
1041634
Fix test/CI issues (#18)
erikc5000 Dec 11, 2019
68bf4c3
Add watchOS and tvOS targets (#19)
erikc5000 Dec 17, 2019
6301b8c
Expand documentation/test coverage, deprecate NsTimeZone.toUtcOffset(…
erikc5000 Dec 22, 2019
02b0ed5
Fix wrong index in StringParser's onEachChar{} (#21)
erikc5000 Dec 26, 2019
20fd0ba
Fix overflow handling when parsing numbers (#22)
erikc5000 Dec 26, 2019
ed5985b
Fix bug in DateTime.millisecondsSinceUnixEpochAt(), increase test cov…
erikc5000 Dec 27, 2019
864f28d
Add download badge to README
erikc5000 Dec 30, 2019
405c1a7
Add artifact with ISO string serializers for kotlinx.serialization (#25)
erikc5000 Jan 8, 2020
1da5bf1
Add locale support (#24)
erikc5000 Jan 10, 2020
3bb21d0
Fix publishing of serialization extensions
erikc5000 Jan 10, 2020
3d1abea
Gradle script clean up
erikc5000 Jan 11, 2020
ce3dc31
Enable debugging for Travis publishing issue
erikc5000 Jan 11, 2020
a8dcb3a
Try build scan to debug publishing issue
erikc5000 Jan 11, 2020
83efa8e
Accept Gradle license terms
erikc5000 Jan 11, 2020
2f53a7a
Try fixing Travis publishing again
erikc5000 Jan 12, 2020
3d6d301
Build fixes, bump AGP and KotlinPoet (#27)
erikc5000 Jan 12, 2020
ad34e4f
Support case-insensitive parsing (#26)
erikc5000 Jan 12, 2020
eb7dd31
By default, respect the system setting for first day of week (#28)
erikc5000 Jan 14, 2020
3bbd22e
Replace Travis with GitHub Actions (#29)
erikc5000 Jan 19, 2020
a6398f6
Update build badge in README
erikc5000 Jan 19, 2020
2dadadc
Replace groups() in GroupedDateTimeParserBuilder with repeat() (#30)
erikc5000 Jan 19, 2020
75c47ad
Work around publishing issue with Gradle project
erikc5000 Jan 20, 2020
a26b5bb
Bump Gradle to 6.1 (#31)
erikc5000 Jan 22, 2020
29cca57
Bump threetenabp to 1.2.2 (#32)
erikc5000 Jan 22, 2020
44a5f54
Bump AGP to 3.6.0-rc02, Dokka to 0.10.1, Gradle to 6.1.1 (#33)
erikc5000 Feb 4, 2020
70d9283
Bump Gradle and AGP versions (#34)
erikc5000 Feb 17, 2020
3b29386
Improve GitHub Actions cache usage (#35)
erikc5000 Feb 17, 2020
a42e985
Duration unit improvements (#36)
erikc5000 Feb 21, 2020
313003b
Split out time zone text from DateTimeTextProvider (#37)
erikc5000 Feb 21, 2020
7533328
Expand the supported year range (#38)
erikc5000 Feb 23, 2020
de8281a
Parser improvements (#39)
erikc5000 Feb 24, 2020
74029aa
Bump Gradle to 6.2.1 and AGP to 3.6.0 final (#40)
erikc5000 Feb 25, 2020
edec062
Fix Instant printing/parsing when DateTime's range is exceeded (#41)
erikc5000 Mar 1, 2020
9050877
Update to Kotlin 1.3.70 (#42)
erikc5000 Mar 6, 2020
a253821
Remove dependency on kotlin-reflect (#43)
erikc5000 Mar 6, 2020
2bfa714
Introduce week range operators (#44)
erikc5000 Mar 11, 2020
9293875
Prepare for 0.2.0 release
erikc5000 Mar 11, 2020
e0df2c1
Merge remote-tracking branch 'origin/master'
erikc5000 Mar 11, 2020
f81db8e
Prepare for next release
erikc5000 Mar 11, 2020
a6d32ef
Remove internal function that accidentally made it into the public AP…
erikc5000 Mar 13, 2020
2677f1d
Add missing hashCode() method to DateTimeInterval (#46)
erikc5000 Mar 13, 2020
d03bdef
Fix minor OffsetDateTimeInterval behavior issues (#47)
erikc5000 Mar 14, 2020
2922abf
Bump Google Truth to 1.0.1, centralize dependency versions (#48)
erikc5000 Mar 14, 2020
8d10415
Add conversions to and from kotlin.time.Duration (#49)
erikc5000 Mar 15, 2020
9890ecd
Add additional conversions to and from Darwin types (#50)
erikc5000 Mar 16, 2020
5f15e3a
Avoid potential library name clashes on native (#51)
erikc5000 Mar 21, 2020
e0915a4
Bump Kotlin to 1.3.71 (#52)
erikc5000 Mar 23, 2020
61deba0
Bump Gradle to 6.3 (#53)
erikc5000 Mar 25, 2020
53c3768
Bump threetenabp to 1.2.3 (#54)
erikc5000 Mar 30, 2020
6548dae
Bump Stately to 1.0.0-a3 (#55)
erikc5000 Mar 30, 2020
e7c9378
Clean up build scripts (#56)
erikc5000 Mar 30, 2020
55c8c11
Prepare for 0.2.1 release
erikc5000 Mar 30, 2020
af8961f
Prepare for next release
erikc5000 Mar 30, 2020
ef6717b
Fix lint issues (#58)
erikc5000 Apr 11, 2020
300d76f
Bump Kotlin to 1.3.72 (#59)
erikc5000 Apr 14, 2020
f526a9e
Fix reversed MIN and MAX on UtcOffset (#60)
erikc5000 Apr 27, 2020
4f4d87c
Improve consistency of Offset*/ZonedDateTime conversion functions/pro…
erikc5000 Apr 30, 2020
7abce9f
Bump Gradle to 6.4.1 (#62)
erikc5000 May 16, 2020
089af30
Bump Stately to 1.0.2-a4 (#63)
erikc5000 May 16, 2020
afea820
Fix interval random() behavior and add randomOrNull() (#64)
erikc5000 May 19, 2020
f4eb275
Fix publishing of atomicfu transitive dependency on native
erikc5000 May 20, 2020
1d73edb
Merge pull request #67 from erikc5000/atomicfu-publish-fix
erikc5000 May 20, 2020
f73a9f9
Add IDEA code style to VCS (#68)
erikc5000 May 20, 2020
a003c2a
Make generateRandom() private instead of internal (#69)
erikc5000 May 20, 2020
4dbc5d1
Documentation improvements (#70)
erikc5000 May 20, 2020
19662e8
Prepare for 0.2.2 release
erikc5000 May 20, 2020
7d270c9
Prepare for next release
erikc5000 May 20, 2020
5594d22
Clean up intervals, enable more code reuse (breaking changes)
erikc5000 May 21, 2020
0129e71
Fix random()/randomOrNull() behavior with half-bounded intervals (#73)
erikc5000 May 22, 2020
5de90c5
Remove duplicated toComponents() code (#74)
erikc5000 May 27, 2020
4726c8c
Rename Unix epoch-related properties/functions for consistency
erikc5000 May 31, 2020
7dd8e29
Expand test coverage
erikc5000 Jun 1, 2020
42a49d7
Rename Unix epoch-related properties/functions for consistency (#75)
erikc5000 Jun 1, 2020
18343d0
Bump KotlinPoet to 1.6.0
erikc5000 Jun 3, 2020
41ce848
Merge pull request #76 from erikc5000/kotlinpoet-1.6.0
erikc5000 Jun 3, 2020
84a0cc0
Improve generated code for duration units (#77)
erikc5000 Jun 4, 2020
1b2d3ca
Bump AGP to 4.0.0 and use core library desugaring in tests (#57)
erikc5000 Jun 18, 2020
117da81
Update the cache action to v2 (#79)
erikc5000 Jun 25, 2020
4b07b6f
Add rounding operators (#80)
erikc5000 Jun 30, 2020
de57ebf
Fix deprecation warning (#81)
erikc5000 Jun 30, 2020
10444e3
Bump threetenabp to 1.2.4 (#83)
erikc5000 Jun 30, 2020
69a80c9
Bump desugar_jdk_libs to 1.0.9 (#82)
erikc5000 Jun 30, 2020
b5af2dc
Bump Gradle to 6.5.1 (#84)
erikc5000 Jun 30, 2020
3c51a2b
Add GitHub Pages documentation (#85)
erikc5000 Jul 2, 2020
a933cc9
Improve documentation some more (#86)
erikc5000 Jul 3, 2020
ae92a6a
Fix property naming inconsistency on Date (#87)
erikc5000 Jul 5, 2020
f424d7d
Tweak GitHub Actions workflows (#89)
erikc5000 Jul 5, 2020
77b4f71
Remove internal usages of deprecated function (#88)
erikc5000 Jul 5, 2020
7410c2f
Merge remote-tracking branch 'remotes/origin/master' into interval-im…
erikc5000 Jul 6, 2020
935159c
Replace deprecated function usage
erikc5000 Jul 6, 2020
f273834
Replace Stately Isolate with a simpler thread confinement implementat…
erikc5000 Jul 12, 2020
a06a786
Clean up Gradle files (#91)
erikc5000 Jul 12, 2020
9903f98
Overhaul conversions between the different date-time and interval typ…
erikc5000 Jul 12, 2020
0267b52
Consolidate rounding operators into single JVM class to help ease fut…
erikc5000 Jul 12, 2020
ff9eb2c
Mention Kotlin 1.4 preview builds in docs (#95)
erikc5000 Jul 12, 2020
b55aab2
Update README to point to project website (#96)
erikc5000 Jul 12, 2020
46215ea
Prepare for 0.2.3 release
erikc5000 Jul 12, 2020
f4f9923
Prepare for next release
erikc5000 Jul 12, 2020
dbd686d
Add CNAME file to docs
erikc5000 Jul 12, 2020
20f1967
Tweak documentation (#97)
erikc5000 Jul 13, 2020
f25485f
Clean up Darwin TimeZoneRulesProvider (#98)
erikc5000 Jul 14, 2020
0d95628
Add missing $ to exception message (#102)
brewin Jul 14, 2020
ecbb589
Move system time zone off of the clock (#99)
erikc5000 Jul 14, 2020
194c920
Bump AGP to 4.0.1 (#100)
erikc5000 Jul 14, 2020
e5ddf36
Deprecate String.toTimeZone() (#103)
erikc5000 Jul 15, 2020
d8385ef
Add week number and year properties (#104)
erikc5000 Jul 23, 2020
630a926
Update docs to reflect addition of week number support (#105)
erikc5000 Jul 23, 2020
789d42a
Enable construction of dates from week date representation (#106)
erikc5000 Jul 25, 2020
cd0b03e
Expand code generation to include conversions between date types (#108)
erikc5000 Jul 25, 2020
57a6bde
KDoc improvements (#107)
erikc5000 Jul 25, 2020
4681490
Rename week range/interval functions, move to code generation (#109)
erikc5000 Jul 25, 2020
e17f0c0
Merge remote-tracking branch 'remotes/origin/master' into interval-im…
erikc5000 Jul 26, 2020
5a45ca7
Add methods to access week-related properties directly using Locale (…
erikc5000 Jul 26, 2020
524da12
Further improve consistency in KDocs (#111)
erikc5000 Jul 26, 2020
8d52db7
Prepare for 0.2.4 release
erikc5000 Jul 26, 2020
33eea2e
Prepare for next release
erikc5000 Jul 26, 2020
68753a6
Remove threentenabp-extensions (#112)
erikc5000 Jul 30, 2020
de87678
Bump Android desugar_sdk_libs to 1.0.10 (#113)
erikc5000 Jul 31, 2020
c177115
Move some date properties to extensions (#114)
erikc5000 Jul 31, 2020
153f8a9
Bump Android minSdkVersion to 21 (#115)
erikc5000 Aug 1, 2020
3576d48
Remove implicit defaultLocale() from APIs, expose locale creation by …
erikc5000 Aug 1, 2020
4206b12
Try to fix website deploy action (#117)
erikc5000 Aug 1, 2020
2fb942e
Re-work clock implementation (#118)
erikc5000 Aug 5, 2020
183f885
Support Kotlin 1.4 (#92)
erikc5000 Aug 5, 2020
ba89a19
Merge remote-tracking branch 'remotes/origin/master' into interval-im…
erikc5000 Aug 5, 2020
50055d4
Merge remote-tracking branch 'remotes/origin/master' into interval-im…
erikc5000 Aug 16, 2020
8a45267
Merge fixes
erikc5000 Aug 16, 2020
3feb08a
Make DateDayProgression an abstract class instead of interface
erikc5000 Aug 17, 2020
21ff495
Fix squashed Kdoc changes
erikc5000 Aug 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ fun ZonedDateTimeInterval.toInstantInterval(): InstantInterval {
return (this as TimePointInterval<*>).toInstantInterval()
}

private inline fun <T> TimeInterval<T>.toDateRange(toDateTime: T.() -> DateTime): DateRange {
private inline fun <T> Interval<T>.toDateRange(toDateTime: T.() -> DateTime): DateRange {
return when {
isEmpty() -> DateRange.EMPTY
isUnbounded() -> DateRange.UNBOUNDED
Expand Down
23 changes: 9 additions & 14 deletions core/src/commonMain/kotlin/io/islandtime/ranges/DateIterators.kt
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package io.islandtime.ranges

import io.islandtime.Date
import io.islandtime.measures.*

abstract class DateIterator : Iterator<Date> {
override fun next() = nextDate()

abstract fun nextDate(): Date
}
import io.islandtime.measures.IntDays
import io.islandtime.measures.IntMonths

internal class DateDayProgressionIterator(
first: LongDays,
last: LongDays,
first: Date,
last: Date,
private val step: IntDays
) : DateIterator() {
) : Iterator<Date> {

private val finalElement = last
private var hasNext = if (step.value > 0) first <= last else first >= last
private var next = if (hasNext) first else finalElement

override fun hasNext() = hasNext

override fun nextDate(): Date {
override fun next(): Date {
val value = next

if (value == finalElement) {
Expand All @@ -34,23 +29,23 @@ internal class DateDayProgressionIterator(
next += step
}

return Date.fromDaysSinceUnixEpoch(value)
return value
}
}

internal class DateMonthProgressionIterator(
first: Date,
last: Date,
private val step: IntMonths
) : DateIterator() {
) : Iterator<Date> {

private val finalElement = last
private var hasNext = if (step.value > 0) first <= last else first >= last
private var next = if (hasNext) first else finalElement

override fun hasNext() = hasNext

override fun nextDate(): Date {
override fun next(): Date {
val value = next

if (value == finalElement) {
Expand Down
104 changes: 51 additions & 53 deletions core/src/commonMain/kotlin/io/islandtime/ranges/DateProgressions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,30 @@ import io.islandtime.internal.MONTHS_PER_YEAR
import io.islandtime.measures.*
import kotlin.math.abs

open class DateDayProgression protected constructor(
first: Date,
abstract class DateDayProgression internal constructor(): Iterable<Date> {
abstract val first: Date
abstract val last: Date
abstract val step: IntDays

/**
* Checks if this progression is empty.
*/
abstract fun isEmpty(): Boolean

override fun iterator(): Iterator<Date> = DateDayProgressionIterator(first, last, step)

companion object {
fun fromClosedRange(rangeStart: Date, rangeEnd: Date, step: IntDays): DateDayProgression {
return DefaultDateDayProgression(rangeStart, rangeEnd, step)
}
}
}

private class DefaultDateDayProgression(
start: Date,
endInclusive: Date,
val step: IntDays
) : Iterable<Date> {
override val step: IntDays
) : DateDayProgression() {

init {
require(step.value != 0) { "Step must be non-zero" }
Expand All @@ -18,45 +37,29 @@ open class DateDayProgression protected constructor(
}
}

protected val firstUnixEpochDay: LongDays = first.daysSinceUnixEpoch
protected val lastUnixEpochDay: LongDays = getLastDayInProgression(firstUnixEpochDay, endInclusive, step)
val first: Date get() = Date.fromDaysSinceUnixEpoch(firstUnixEpochDay)
val last: Date get() = Date.fromDaysSinceUnixEpoch(lastUnixEpochDay)

/**
* Checks if this progression is empty.
*/
open fun isEmpty(): Boolean = if (step.value > 0) first > last else first < last
override val first: Date = start
override val last: Date = getLastDateInProgression(start, endInclusive, step)

override fun iterator(): DateIterator = DateDayProgressionIterator(firstUnixEpochDay, lastUnixEpochDay, step)
override fun isEmpty(): Boolean = if (step.value > 0) first > last else first < last

override fun toString() = if (step.value > 0) "$first..$last step $step" else "$first downTo $last step ${-step}"

override fun equals(other: Any?): Boolean {
return other is DateDayProgression &&
(isEmpty() && other.isEmpty() ||
firstUnixEpochDay == other.firstUnixEpochDay &&
lastUnixEpochDay == other.lastUnixEpochDay &&
step == other.step)
((isEmpty() && other.isEmpty()) || (first == other.first && last == other.last && step == other.step))
}

override fun hashCode(): Int {
return if (isEmpty()) {
-1
} else {
31 * (31 * firstUnixEpochDay.hashCode() + lastUnixEpochDay.hashCode()) + step.value
}
}

companion object {
fun fromClosedRange(rangeStart: Date, rangeEnd: Date, step: IntDays): DateDayProgression {
return DateDayProgression(rangeStart, rangeEnd, step)
31 * (31 * first.hashCode() + last.hashCode()) + step.value
}
}
}

class DateMonthProgression private constructor(
val first: Date,
start: Date,
endInclusive: Date,
val step: IntMonths
) : Iterable<Date> {
Expand All @@ -65,32 +68,29 @@ class DateMonthProgression private constructor(
require(step.value != 0) { "Step must be non-zero" }
}

val last = getLastDateInProgression(first, endInclusive, step)
val first = start
val last = getLastDateInProgression(start, endInclusive, step)

/**
* Checks if this progression is empty.
*/
fun isEmpty(): Boolean = if (step.value > 0) first > last else first < last

override fun iterator(): DateIterator = DateMonthProgressionIterator(first, last, step)
override fun iterator(): Iterator<Date> = DateMonthProgressionIterator(first, last, step)

override fun toString() = if (step.value > 0) "$first..$last step $step" else "$first downTo $last step ${-step}"

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false

other as DateMonthProgression

if (first != other.first) return false
if (step != other.step) return false
if (last != other.last) return false

return true
return other is DateMonthProgression &&
((isEmpty() && other.isEmpty()) || (first == other.first && last == other.last && step == other.step))
}

override fun hashCode(): Int {
return if (isEmpty()) -1 else 31 * (31 * first.hashCode() + last.hashCode()) + step.value
return if (isEmpty()) {
-1
} else {
31 * (31 * first.hashCode() + last.hashCode()) + step.value
}
}

companion object {
Expand Down Expand Up @@ -154,27 +154,25 @@ fun DateMonthProgression.reversed() = DateMonthProgression.fromClosedRange(last,
/**
* Assumes step is non-zero
*/
private fun getLastDayInProgression(startInDays: LongDays, endDate: Date, step: IntDays): LongDays {
val endInDays = endDate.daysSinceUnixEpoch

private fun getLastDateInProgression(start: Date, end: Date, step: IntDays): Date {
return when {
step.value > 0L -> if (startInDays >= endInDays) {
endInDays
step.value > 0L -> if (start >= end) {
end
} else {
endInDays - (abs(endInDays.value - startInDays.value) % step.value).days
val endEpochDay = end.dayOfUnixEpoch
Date.fromDayOfUnixEpoch(endEpochDay - (abs(endEpochDay - start.dayOfUnixEpoch) % step.value))
}
else -> if (startInDays <= endInDays) {
endInDays
else -> if (start <= end) {
end
} else {
endInDays - (abs(startInDays.value - endInDays.value) % step.value).days
val endEpochDay = end.dayOfUnixEpoch
Date.fromDayOfUnixEpoch(endEpochDay - (abs(start.dayOfUnixEpoch - end.dayOfUnixEpoch) % step.value))
}
}
}

private fun getLastDateInProgression(start: Date, end: Date, step: IntMonths): Date {
return if ((step.value > 0 && start >= end) ||
(step.value < 0 && start <= end)
) {
return if ((step.value > 0 && start >= end) || (step.value < 0 && start <= end)) {
end
} else {
val monthsBetween = progressionMonthsBetween(start, end)
Expand All @@ -184,11 +182,11 @@ private fun getLastDateInProgression(start: Date, end: Date, step: IntMonths): D
}

/**
* Gets the number of months between two dates for the purposes of a progression. This works a little differently than
* Gets the number of months between two dates for the purposes of a progression. This works a little differently than
* the usual [monthsBetween] since it tries to use the same day as the start date while stepping months, coercing that
* day as needed to fit the number of days in the current month.
*/
internal fun progressionMonthsBetween(start: Date, endInclusive: Date): IntMonths {
private fun progressionMonthsBetween(start: Date, endInclusive: Date): IntMonths {
val yearsBetween = endInclusive.year - start.year
val monthsBetween = yearsBetween * MONTHS_PER_YEAR + (endInclusive.month.ordinal - start.month.ordinal)

Expand Down
60 changes: 22 additions & 38 deletions core/src/commonMain/kotlin/io/islandtime/ranges/DateRange.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.islandtime.base.DateTimeField
import io.islandtime.internal.MONTHS_PER_YEAR
import io.islandtime.measures.*
import io.islandtime.parser.*
import io.islandtime.ranges.internal.buildIsoString
import io.islandtime.ranges.internal.throwUnboundedIntervalException
import kotlin.random.Random
import kotlin.random.nextLong
Expand All @@ -13,62 +14,45 @@ import kotlin.random.nextLong
* An inclusive range of dates.
*
* [Date.MIN] and [Date.MAX] are used as sentinels to indicate an unbounded (ie. infinite) start or end.
*
* @property start The start of this interval, inclusive.
* @property endInclusive The end of this interval, inclusive.
*/
class DateRange(
start: Date = Date.MIN,
endInclusive: Date = Date.MAX
) : DateDayProgression(start, endInclusive, 1.days),
override val start: Date = Date.MIN,
override val endInclusive: Date = Date.MAX
) : DateDayProgression(),
Interval<Date>,
ClosedRange<Date> {

fun hasUnboundedStart(): Boolean = start == Date.MIN
fun hasUnboundedEnd(): Boolean = endInclusive == Date.MAX
override val endExclusive: Date get() = endInclusive + 1.days

fun hasBoundedStart(): Boolean = !hasUnboundedStart()
fun hasBoundedEnd(): Boolean = !hasUnboundedEnd()
fun isBounded(): Boolean = hasBoundedStart() && hasBoundedEnd()
fun isUnbounded(): Boolean = hasUnboundedStart() && hasUnboundedEnd()
override fun hasUnboundedStart(): Boolean = start == Date.MIN
override fun hasUnboundedEnd(): Boolean = endInclusive == Date.MAX
override fun contains(value: Date): Boolean = super.contains(value)

override val start: Date get() = first
override val endInclusive: Date get() = last
override val first: Date get() = start
override val last: Date get() = endInclusive
override val step: IntDays get() = 1.days

override fun isEmpty(): Boolean {
return firstUnixEpochDay > lastUnixEpochDay || endInclusive == Date.MIN || start == Date.MAX
return start > endInclusive || endInclusive == Date.MIN || start == Date.MAX
}

/**
* Converts this range to a string in ISO-8601 extended format.
*/
override fun toString(): String {
return if (isEmpty()) {
""
} else {
buildString(2 * MAX_DATE_STRING_LENGTH + 1) {
if (hasBoundedStart()) {
appendDate(start)
} else {
append("..")
}

append('/')

if (hasBoundedEnd()) {
appendDate(endInclusive)
} else {
append("..")
}
}
}
}
override fun toString(): String = buildIsoString(
maxElementSize = MAX_DATE_STRING_LENGTH,
inclusive = true,
appendFunction = StringBuilder::appendDate
)

override fun equals(other: Any?): Boolean {
return other is DateRange && (isEmpty() && other.isEmpty() || first == other.first && last == other.last)
return other is DateRange &&
((isEmpty() && other.isEmpty()) ||
(start == other.start && endInclusive == other.endInclusive))
}

override fun hashCode(): Int {
return if (isEmpty()) -1 else (31 * first.hashCode() + last.hashCode())
return if (isEmpty()) -1 else (31 * start.hashCode() + endInclusive.hashCode())
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import kotlin.random.Random
class DateTimeInterval(
override val start: DateTime = UNBOUNDED.start,
override val endExclusive: DateTime = UNBOUNDED.endExclusive
) : TimeInterval<DateTime> {
) : Interval<DateTime> {

override val endInclusive: DateTime
get() = if (hasUnboundedEnd()) endExclusive else endExclusive - 1.nanoseconds

override fun hasUnboundedStart(): Boolean = start == DateTime.MIN
override fun hasUnboundedEnd(): Boolean = endExclusive == DateTime.MAX
Expand Down Expand Up @@ -45,7 +48,11 @@ class DateTimeInterval(
/**
* Converts this interval to a string in ISO-8601 extended format.
*/
override fun toString() = buildIsoString(MAX_DATE_TIME_STRING_LENGTH, StringBuilder::appendDateTime)
override fun toString() = buildIsoString(
maxElementSize = MAX_DATE_TIME_STRING_LENGTH,
inclusive = false,
appendFunction = StringBuilder::appendDateTime
)

/**
* Converts this interval to the [Duration] between the start and end date-time, assuming they're in the same time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ class InstantInterval(
/**
* Converts this interval to a string in ISO-8601 extended format.
*/
override fun toString() = buildIsoString(MAX_INSTANT_STRING_LENGTH, StringBuilder::appendInstant)
override fun toString() = buildIsoString(
maxElementSize = MAX_INSTANT_STRING_LENGTH,
inclusive = false,
appendFunction = StringBuilder::appendInstant
)

companion object {
/**
Expand Down
Loading