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

Rename week range/interval functions, move to code generation #109

Merged
merged 1 commit into from
Jul 25, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Features:
- Read and write strings in ISO formats
- DSL-based definition of custom parsers
- Access localized text for names of months, days of the week, time zones, etc.
- Convenience operators like `date.next(MONDAY)`, `dateTime.startOfWeek`, or `date.weekRange(WeekSettings.systemDefault())`
- Convenience operators like `date.next(MONDAY)`, `dateTime.startOfWeek`, or `date.week(WeekSettings.systemDefault())`
- Convert to and from platform-specific date-time types
- Works on JVM, Android, iOS, macOS, tvOS, and watchOS

Expand Down
110 changes: 110 additions & 0 deletions core/src/commonMain/generated/io/islandtime/_DateProperties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,43 @@ import io.islandtime.internal.weekBasedYearImpl
import io.islandtime.internal.weekOfMonthImpl
import io.islandtime.internal.weekOfWeekBasedYearImpl
import io.islandtime.internal.weekOfYearImpl
import io.islandtime.locale.Locale
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
import io.islandtime.ranges.ZonedDateTimeInterval
import io.islandtime.ranges.until
import kotlin.Int
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
* The range defining the ISO week that this date falls within.
*
* The ISO week starts on Monday and ends on Sunday.
*/
val Date.week: DateRange
get() = startOfWeek.let { it..it + 6.days }

/**
* The range defining the week that this date falls within. The first day of the week will be
* determined by the provided [settings].
*/
fun Date.week(settings: WeekSettings): DateRange = startOfWeek(settings).let { it..it + 6.days }

/**
* The range defining the week that this date falls within. The first day of the week will be the
* default associated with the provided [locale].
*
* Keep in mind that that the system's calendar settings may differ from that of the default locale
* on some platforms. To respect the system calendar settings, use [WeekSettings.systemDefault]
* instead.
*/
fun Date.week(locale: Locale): DateRange = startOfWeek(locale).let { it..it + 6.days }

/**
* The week of the month (0-5) according to the ISO definition.
*/
Expand Down Expand Up @@ -88,6 +120,32 @@ fun Date.weekOfWeekBasedYear(settings: WeekSettings): Int = weekOfWeekBasedYearI
val Date.lengthOfWeekBasedYear: IntWeeks
get() = lengthOfWeekBasedYear(weekBasedYear)

/**
* The interval defining the ISO week that this date-time falls within.
*
* The ISO week starts on Monday and ends on Sunday.
*/
val DateTime.week: DateTimeInterval
get() = startOfWeek.let { it until it + 7.days }

/**
* The interval defining the week that this date-time falls within. The first day of the week will
* be determined by the provided [settings].
*/
fun DateTime.week(settings: WeekSettings): DateTimeInterval =
startOfWeek(settings).let { it until it + 7.days }

/**
* The interval defining the week that this date-time falls within. The first day of the week will
* be the default associated with the provided [locale].
*
* Keep in mind that that the system's calendar settings may differ from that of the default locale
* on some platforms. To respect the system calendar settings, use [WeekSettings.systemDefault]
* instead.
*/
fun DateTime.week(locale: Locale): DateTimeInterval =
startOfWeek(locale).let { it until it + 7.days }

/**
* The week of the month (0-5) according to the ISO definition.
*/
Expand Down Expand Up @@ -159,6 +217,32 @@ fun DateTime.weekOfWeekBasedYear(settings: WeekSettings): Int = date.weekOfWeekB
val DateTime.lengthOfWeekBasedYear: IntWeeks
inline get() = date.lengthOfWeekBasedYear

/**
* The interval defining the ISO week that this date-time falls within.
*
* The ISO week starts on Monday and ends on Sunday.
*/
val OffsetDateTime.week: OffsetDateTimeInterval
get() = startOfWeek.let { it until it + 7.days }

/**
* The interval defining the week that this date-time falls within. The first day of the week will
* be determined by the provided [settings].
*/
fun OffsetDateTime.week(settings: WeekSettings): OffsetDateTimeInterval =
startOfWeek(settings).let { it until it + 7.days }

/**
* The interval defining the week that this date-time falls within. The first day of the week will
* be the default associated with the provided [locale].
*
* Keep in mind that that the system's calendar settings may differ from that of the default locale
* on some platforms. To respect the system calendar settings, use [WeekSettings.systemDefault]
* instead.
*/
fun OffsetDateTime.week(locale: Locale): OffsetDateTimeInterval =
startOfWeek(locale).let { it until it + 7.days }

/**
* The week of the month (0-5) according to the ISO definition.
*/
Expand Down Expand Up @@ -231,6 +315,32 @@ fun OffsetDateTime.weekOfWeekBasedYear(settings: WeekSettings): Int =
val OffsetDateTime.lengthOfWeekBasedYear: IntWeeks
inline get() = dateTime.lengthOfWeekBasedYear

/**
* The interval defining the ISO week that this date-time falls within.
*
* The ISO week starts on Monday and ends on Sunday.
*/
val ZonedDateTime.week: ZonedDateTimeInterval
get() = startOfWeek.let { it until it + 7.days }

/**
* The interval defining the week that this date-time falls within. The first day of the week will
* be determined by the provided [settings].
*/
fun ZonedDateTime.week(settings: WeekSettings): ZonedDateTimeInterval =
startOfWeek(settings).let { it until it + 7.days }

/**
* The interval defining the week that this date-time falls within. The first day of the week will
* be the default associated with the provided [locale].
*
* Keep in mind that that the system's calendar settings may differ from that of the default locale
* on some platforms. To respect the system calendar settings, use [WeekSettings.systemDefault]
* instead.
*/
fun ZonedDateTime.week(locale: Locale): ZonedDateTimeInterval =
startOfWeek(locale).let { it until it + 7.days }

/**
* The week of the month (0-5) according to the ISO definition.
*/
Expand Down
135 changes: 72 additions & 63 deletions core/src/commonMain/kotlin/io/islandtime/operators/Week.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,93 +9,102 @@ import io.islandtime.locale.Locale
import io.islandtime.measures.days
import io.islandtime.ranges.*

/**
* The date range of the ISO week that this date falls within.
*
* The ISO week starts on Monday and ends on Sunday.
*/
@Deprecated(
"Renamed to 'week'.",
ReplaceWith("this.week", "io.islandtime.week"),
DeprecationLevel.WARNING
)
val Date.weekRange: DateRange
get() = with(startOfWeek) { this..this + 6.days }
get() = startOfWeek.let { it..it + 6.days }

/**
* The date range of the week that this date falls within. The first day of the week will be determined by [settings].
*/
fun Date.weekRange(settings: WeekSettings): DateRange = with(startOfWeek(settings)) { this..this + 6.days }
@Deprecated(
"Renamed to 'week'.",
ReplaceWith("this.week(settings)", "io.islandtime.week"),
DeprecationLevel.WARNING
)
fun Date.weekRange(settings: WeekSettings): DateRange = startOfWeek(settings).let { it..it + 6.days }

/**
* The date range of the week that this date falls within. The first day of the week will be determined by [locale].
*/
fun Date.weekRange(locale: Locale): DateRange = with(startOfWeek(locale)) { this..this + 6.days }
@Deprecated(
"Renamed to 'week'.",
ReplaceWith("this.week(locale)", "io.islandtime.week"),
DeprecationLevel.WARNING
)
fun Date.weekRange(locale: Locale): DateRange = startOfWeek(locale).let { it..it + 6.days }

/**
* The interval of the ISO week that this date-time falls within.
*
* The ISO week starts on Monday and ends on Sunday.
*/
@Deprecated(
"Renamed to 'week'.",
ReplaceWith("this.week", "io.islandtime.week"),
DeprecationLevel.WARNING
)
val DateTime.weekInterval: DateTimeInterval
get() = with(startOfWeek) { this until this + 7.days }
get() = startOfWeek.let { it until it + 7.days }

/**
* The interval of the week that this date-time falls within. The first day of the week will be determined by
* [settings].
*/
@Deprecated(
"Renamed to 'week'.",
ReplaceWith("this.week(settings)", "io.islandtime.week"),
DeprecationLevel.WARNING
)
fun DateTime.weekInterval(settings: WeekSettings): DateTimeInterval {
return with(startOfWeek(settings)) { this until this + 7.days }
return startOfWeek(settings).let { it until it + 7.days }
}

/**
* The interval of the week that this date falls within. The first day of the week will be determined by [locale].
*/
@Deprecated(
"Renamed to 'week'.",
ReplaceWith("this.week(locale)", "io.islandtime.week"),
DeprecationLevel.WARNING
)
fun DateTime.weekInterval(locale: Locale): DateTimeInterval {
return with(startOfWeek(locale)) { this until this + 7.days }
return startOfWeek(locale).let { it until it + 7.days }
}

/**
* The interval of the ISO week that this date-time falls within. The offset will be preserved in both the start and end
* date-times
*
* The ISO week starts on Monday and ends on Sunday.
*/
@Deprecated(
"Renamed to 'week'.",
ReplaceWith("this.week", "io.islandtime.week"),
DeprecationLevel.WARNING
)
val OffsetDateTime.weekInterval: OffsetDateTimeInterval
get() = with(startOfWeek) { this until this + 7.days }
get() = startOfWeek.let { it until it + 7.days }

/**
* The interval of the week that this date-time falls within. The first day of the week will be determined by
* [settings]. The offset will be preserved in both the start and end date-times.
*/
@Deprecated(
"Renamed to 'week'.",
ReplaceWith("this.week(settings)", "io.islandtime.week"),
DeprecationLevel.WARNING
)
fun OffsetDateTime.weekInterval(settings: WeekSettings): OffsetDateTimeInterval {
return with(startOfWeek(settings)) { this until this + 7.days }
return startOfWeek(settings).let { it until it + 7.days }
}

/**
* The interval of the week that this date falls within. The first day of the week will be determined by [locale]. The
* offset will be preserved in both the start and end date-times.
*/
@Deprecated(
"Renamed to 'week'.",
ReplaceWith("this.week(locale)", "io.islandtime.week"),
DeprecationLevel.WARNING
)
fun OffsetDateTime.weekInterval(locale: Locale): OffsetDateTimeInterval {
return with(startOfWeek(locale)) { this until this + 7.days }
return startOfWeek(locale).let { it until it + 7.days }
}

/**
* The interval of the ISO week that this date-time falls within. The zone will be preserved in both the start and end
* date-times.
*
* The ISO week starts on Monday and ends on Sunday.
*/
@Deprecated(
"Renamed to 'week'.",
ReplaceWith("this.week", "io.islandtime.week"),
DeprecationLevel.WARNING
)
val ZonedDateTime.weekInterval: ZonedDateTimeInterval
get() = with(startOfWeek) { this until this + 7.days }
get() = startOfWeek.let { it until it + 7.days }

/**
* The interval of the week that this date-time falls within. The first day of the week will be determined by
* [settings]. The zone will be preserved in both the start and end date-times.
*/
@Deprecated(
"Renamed to 'week'.",
ReplaceWith("this.week(settings)", "io.islandtime.week"),
DeprecationLevel.WARNING
)
fun ZonedDateTime.weekInterval(settings: WeekSettings): ZonedDateTimeInterval {
return with(startOfWeek(settings)) { this until this + 7.days }
return startOfWeek(settings).let { it until it + 7.days }
}

/**
* The interval of the week that this date falls within. The first day of the week will be determined by [locale]. The
* zone will be preserved in both the start and end date-times.
*/
@Deprecated(
"Renamed to 'week'.",
ReplaceWith("this.week(locale)", "io.islandtime.week"),
DeprecationLevel.WARNING
)
fun ZonedDateTime.weekInterval(locale: Locale): ZonedDateTimeInterval {
return with(startOfWeek(locale)) { this until this + 7.days }
return startOfWeek(locale).let { it until it + 7.days }
}
Loading