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

Re-organize package structure #131

Merged
merged 2 commits into from
Aug 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 0 additions & 4 deletions core/MODULE.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ Platform-independent locale.

Classes related to the measurement of time, including `Duration`, `Period`, and more specific units, such as `IntHours` or `LongYears`.

# Package io.islandtime.operators

Convenience operators for various date-time primitives, enabling things like `date.next(TUESDAY)`, `date.startOfWeek`, or `dateTime.truncatedTo(HOURS)`.

# Package io.islandtime.parser

Parsing of dates, times, durations, and intervals from textual representations.
Expand Down
225 changes: 166 additions & 59 deletions core/src/commonMain/generated/io/islandtime/_DateProperties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import io.islandtime.locale.Locale
import io.islandtime.measures.IntDays
import io.islandtime.measures.IntWeeks
import io.islandtime.measures.days
import io.islandtime.operators.startOfWeek
import io.islandtime.ranges.DateRange
import io.islandtime.ranges.DateTimeInterval
import io.islandtime.ranges.OffsetDateTimeInterval
Expand All @@ -28,30 +27,6 @@ import kotlin.Int
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
* Checks if this date falls within a leap year.
*/
val Date.isInLeapYear: Boolean
get() = isLeapYear(year)

/**
* Checks if this date is February 29.
*/
val Date.isLeapDay: Boolean
get() = month == Month.FEBRUARY && dayOfMonth == 29

/**
* The length of this date's month in days.
*/
val Date.lengthOfMonth: IntDays
get() = month.lengthIn(year)

/**
* The length of this date's year in days.
*/
val Date.lengthOfYear: IntDays
get() = lengthOfYear(year)

/**
* The range defining the ISO week that this date falls within.
*
Expand Down Expand Up @@ -190,35 +165,73 @@ fun Date.weekOfWeekBasedYear(settings: WeekSettings): Int = weekOfWeekBasedYearI
*/
fun Date.weekOfWeekBasedYear(locale: Locale): Int = weekOfWeekBasedYearImpl(locale.weekSettings)

/**
* Checks if this date falls within a leap year.
*/
val Date.isInLeapYear: Boolean
get() = isLeapYear(year)

/**
* Checks if this date is February 29.
*/
val Date.isLeapDay: Boolean
get() = month == Month.FEBRUARY && dayOfMonth == 29

/**
* The length of this date's month in days.
*/
val Date.lengthOfMonth: IntDays
get() = month.lengthIn(year)

/**
* The length of this date's year in days.
*/
val Date.lengthOfYear: IntDays
get() = lengthOfYear(year)

/**
* The length of the ISO week-based year that this date falls in, either 52 or 53 weeks.
*/
val Date.lengthOfWeekBasedYear: IntWeeks
get() = lengthOfWeekBasedYear(weekBasedYear)

/**
* Checks if this date-time falls within a leap year.
* The next date after this one that falls on [dayOfWeek].
*/
val DateTime.isInLeapYear: Boolean
inline get() = date.isInLeapYear
fun Date.next(dayOfWeek: DayOfWeek): Date {
val dayDiff = this.dayOfWeek.ordinal - dayOfWeek.ordinal

return if (dayDiff >= 0) {
this + (7 - dayDiff).days
} else {
this + (-dayDiff).days
}
}

/**
* Checks if this date-time falls within February 29.
* The next date that falls on [dayOfWeek], or this date if it falls on the same day.
*/
val DateTime.isInLeapDay: Boolean
inline get() = date.isLeapDay
fun Date.nextOrSame(dayOfWeek: DayOfWeek): Date = if (dayOfWeek == this.dayOfWeek) this else
next(dayOfWeek)

/**
* The length of this date-time's month in days.
* The last date before this one that falls on [dayOfWeek].
*/
val DateTime.lengthOfMonth: IntDays
inline get() = date.lengthOfMonth
fun Date.previous(dayOfWeek: DayOfWeek): Date {
val dayDiff = dayOfWeek.ordinal - this.dayOfWeek.ordinal

return if (dayDiff >= 0) {
this - (7 - dayDiff).days
} else {
this - (-dayDiff).days
}
}

/**
* The length of this date-time's year in days.
* The previous date that falls on [dayOfWeek], or this date if it falls on the same day.
*/
val DateTime.lengthOfYear: IntDays
inline get() = date.lengthOfYear
fun Date.previousOrSame(dayOfWeek: DayOfWeek): Date = if (dayOfWeek == this.dayOfWeek) this else
previous(dayOfWeek)

/**
* The interval defining the ISO week that this date-time falls within.
Expand Down Expand Up @@ -360,35 +373,57 @@ fun DateTime.weekOfWeekBasedYear(settings: WeekSettings): Int = date.weekOfWeekB
*/
fun DateTime.weekOfWeekBasedYear(locale: Locale): Int = date.weekOfWeekBasedYear(locale)

/**
* Checks if this date-time falls within a leap year.
*/
val DateTime.isInLeapYear: Boolean
inline get() = date.isInLeapYear

/**
* Checks if this date-time falls within February 29.
*/
val DateTime.isInLeapDay: Boolean
inline get() = date.isLeapDay

/**
* The length of this date-time's month in days.
*/
val DateTime.lengthOfMonth: IntDays
inline get() = date.lengthOfMonth

/**
* The length of this date-time's year in days.
*/
val DateTime.lengthOfYear: IntDays
inline get() = date.lengthOfYear

/**
* The length of the ISO week-based year that this date-time falls in, either 52 or 53 weeks.
*/
val DateTime.lengthOfWeekBasedYear: IntWeeks
inline get() = date.lengthOfWeekBasedYear

/**
* Checks if this date-time falls within a leap year.
* The next date-time after this one that falls on [dayOfWeek].
*/
val OffsetDateTime.isInLeapYear: Boolean
inline get() = dateTime.isInLeapYear
fun DateTime.next(dayOfWeek: DayOfWeek): DateTime = copy(date = date.next(dayOfWeek))

/**
* Checks if this date-time falls within February 29.
* The next date-time that falls on [dayOfWeek], or this date-time if it falls on the same day.
*/
val OffsetDateTime.isInLeapDay: Boolean
inline get() = date.isLeapDay
fun DateTime.nextOrSame(dayOfWeek: DayOfWeek): DateTime = if (dayOfWeek == this.dayOfWeek) this else
next(dayOfWeek)

/**
* The length of this date-time's month in days.
* The last date-time before this one that falls on [dayOfWeek].
*/
val OffsetDateTime.lengthOfMonth: IntDays
inline get() = dateTime.lengthOfMonth
fun DateTime.previous(dayOfWeek: DayOfWeek): DateTime = copy(date = date.previous(dayOfWeek))

/**
* The length of this date-time's year in days.
* The previous date-time that falls on [dayOfWeek], or this date-time if it falls on the same day.
*/
val OffsetDateTime.lengthOfYear: IntDays
inline get() = dateTime.lengthOfYear
fun DateTime.previousOrSame(dayOfWeek: DayOfWeek): DateTime = if (dayOfWeek == this.dayOfWeek) this
else previous(dayOfWeek)

/**
* The interval defining the ISO week that this date-time falls within.
Expand Down Expand Up @@ -531,36 +566,60 @@ fun OffsetDateTime.weekOfWeekBasedYear(settings: WeekSettings): Int =
*/
fun OffsetDateTime.weekOfWeekBasedYear(locale: Locale): Int = dateTime.weekOfWeekBasedYear(locale)

/**
* The length of the ISO week-based year that this date-time falls in, either 52 or 53 weeks.
*/
val OffsetDateTime.lengthOfWeekBasedYear: IntWeeks
inline get() = dateTime.lengthOfWeekBasedYear

/**
* Checks if this date-time falls within a leap year.
*/
val ZonedDateTime.isInLeapYear: Boolean
val OffsetDateTime.isInLeapYear: Boolean
inline get() = dateTime.isInLeapYear

/**
* Checks if this date-time falls within February 29.
*/
val ZonedDateTime.isInLeapDay: Boolean
val OffsetDateTime.isInLeapDay: Boolean
inline get() = date.isLeapDay

/**
* The length of this date-time's month in days.
*/
val ZonedDateTime.lengthOfMonth: IntDays
val OffsetDateTime.lengthOfMonth: IntDays
inline get() = dateTime.lengthOfMonth

/**
* The length of this date-time's year in days.
*/
val ZonedDateTime.lengthOfYear: IntDays
val OffsetDateTime.lengthOfYear: IntDays
inline get() = dateTime.lengthOfYear

/**
* The length of the ISO week-based year that this date-time falls in, either 52 or 53 weeks.
*/
val OffsetDateTime.lengthOfWeekBasedYear: IntWeeks
inline get() = dateTime.lengthOfWeekBasedYear

/**
* The next date-time after this one that falls on [dayOfWeek].
*/
fun OffsetDateTime.next(dayOfWeek: DayOfWeek): OffsetDateTime = copy(dateTime =
dateTime.next(dayOfWeek))

/**
* The next date-time that falls on [dayOfWeek], or this date-time if it falls on the same day.
*/
fun OffsetDateTime.nextOrSame(dayOfWeek: DayOfWeek): OffsetDateTime = if (dayOfWeek ==
this.dayOfWeek) this else next(dayOfWeek)

/**
* The last date-time before this one that falls on [dayOfWeek].
*/
fun OffsetDateTime.previous(dayOfWeek: DayOfWeek): OffsetDateTime = copy(dateTime =
dateTime.previous(dayOfWeek))

/**
* The previous date-time that falls on [dayOfWeek], or this date-time if it falls on the same day.
*/
fun OffsetDateTime.previousOrSame(dayOfWeek: DayOfWeek): OffsetDateTime = if (dayOfWeek ==
this.dayOfWeek) this else previous(dayOfWeek)

/**
* The interval defining the ISO week that this date-time falls within.
*
Expand Down Expand Up @@ -702,8 +761,56 @@ fun ZonedDateTime.weekOfWeekBasedYear(settings: WeekSettings): Int =
*/
fun ZonedDateTime.weekOfWeekBasedYear(locale: Locale): Int = dateTime.weekOfWeekBasedYear(locale)

/**
* Checks if this date-time falls within a leap year.
*/
val ZonedDateTime.isInLeapYear: Boolean
inline get() = dateTime.isInLeapYear

/**
* Checks if this date-time falls within February 29.
*/
val ZonedDateTime.isInLeapDay: Boolean
inline get() = date.isLeapDay

/**
* The length of this date-time's month in days.
*/
val ZonedDateTime.lengthOfMonth: IntDays
inline get() = dateTime.lengthOfMonth

/**
* The length of this date-time's year in days.
*/
val ZonedDateTime.lengthOfYear: IntDays
inline get() = dateTime.lengthOfYear

/**
* The length of the ISO week-based year that this date-time falls in, either 52 or 53 weeks.
*/
val ZonedDateTime.lengthOfWeekBasedYear: IntWeeks
inline get() = dateTime.lengthOfWeekBasedYear

/**
* The next date-time after this one that falls on [dayOfWeek].
*/
fun ZonedDateTime.next(dayOfWeek: DayOfWeek): ZonedDateTime = copy(dateTime =
dateTime.next(dayOfWeek))

/**
* The next date-time that falls on [dayOfWeek], or this date-time if it falls on the same day.
*/
fun ZonedDateTime.nextOrSame(dayOfWeek: DayOfWeek): ZonedDateTime = if (dayOfWeek == this.dayOfWeek)
this else next(dayOfWeek)

/**
* The last date-time before this one that falls on [dayOfWeek].
*/
fun ZonedDateTime.previous(dayOfWeek: DayOfWeek): ZonedDateTime = copy(dateTime =
dateTime.previous(dayOfWeek))

/**
* The previous date-time that falls on [dayOfWeek], or this date-time if it falls on the same day.
*/
fun ZonedDateTime.previousOrSame(dayOfWeek: DayOfWeek): ZonedDateTime = if (dayOfWeek ==
this.dayOfWeek) this else previous(dayOfWeek)
Loading