Skip to content

Commit

Permalink
Kotlin 1.4.0-rc
Browse files Browse the repository at this point in the history
  • Loading branch information
fluidsonic committed Jul 29, 2020
1 parent 5cf00dd commit 6e2c838
Show file tree
Hide file tree
Showing 76 changed files with 840 additions and 839 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: macOS
runs-on: macos-latest
env:
GRADLE_OPTS: -Dorg.gradle.jvmargs=-Xmx1g
GRADLE_OPTS: -Dorg.gradle.jvmargs=-Xmx4g
steps:
- uses: actions/checkout@v1
- run: xcodebuild -version
Expand All @@ -20,10 +20,19 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java_version: ['1.8', '9', '10', '11', '12', '13']
java_version: ['8', '9', '10', '11', '12', '13']
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java_version }}
- run: ./gradlew jdk7test jdk8Test
- run: ./gradlew jvmTest
jdk:
name: JDK 7
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: 7
- run: ./gradlew jvmJdk7test
9 changes: 9 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/saveactions_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ fluid-time
[![Maven Central](https://img.shields.io/maven-central/v/io.fluidsonic.time/fluid-time?label=Maven%20Central)](https://search.maven.org/artifact/io.fluidsonic.time/fluid-time)
[![JCenter](https://img.shields.io/bintray/v/fluidsonic/kotlin/time?label=JCenter)](https://bintray.com/fluidsonic/kotlin/time)
[![Tests](https://github.com/fluidsonic/fluid-time/workflows/Tests/badge.svg)](https://github.com/fluidsonic/fluid-time/actions?workflow=Tests)
[![Kotlin](https://img.shields.io/badge/Kotlin-1.3.72-blue.svg)](https://github.com/JetBrains/kotlin/releases/v1.3.72)
[![Kotlin](https://img.shields.io/badge/Kotlin-1.4.0--rc-blue.svg)](https://github.com/JetBrains/kotlin/releases/v1.4.0-rc)
[![#fluid-libraries Slack Channel](https://img.shields.io/badge/slack-%23fluid--libraries-543951.svg?label=Slack)](https://kotlinlang.slack.com/messages/C7UDFSVT2/)

Multiplatform date & time library.
Multiplatform date & time library.
Very early stage.


Expand Down
48 changes: 13 additions & 35 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,48 +1,26 @@
import io.fluidsonic.gradle.*

plugins {
id("io.fluidsonic.gradle") version "1.0.13"
id("io.fluidsonic.gradle") version "1.1.0"
}

fluidLibrary(name = "time", version = "0.9.20")

fluidLibraryVariant {
description = "Multiplatform date & time library"

common {
dependencies {
implementation(kotlinx("serialization-runtime-common", "0.20.0"))
fluidLibraryModule(description = "Multiplatform date & time library") {
targets {
common {
dependencies {
implementation(kotlinx("serialization-runtime", "1.0-M1-1.4.0-rc"))
}
}
}

jvm(JvmTarget.jdk7) {
dependencies {
implementation(kotlinx("serialization-runtime", "0.20.0"))
implementation("org.threeten:threetenbp:1.4.4")
jvm()
jvmJdk7 {
dependencies {
implementation("org.threeten:threetenbp:1.4.4")
}
}
}

jvm(JvmTarget.jdk8) {
dependencies {
implementation(kotlinx("serialization-runtime", "0.20.0"))
}
}

objc(ObjcTarget.iosArm64) {
dependencies {
implementation(kotlinx("serialization-runtime-iosarm64", "0.20.0"))
}
}

objc(ObjcTarget.iosX64) {
dependencies {
implementation(kotlinx("serialization-runtime-iosx64", "0.20.0"))
}
}

objc(ObjcTarget.macosX64) {
dependencies {
implementation(kotlinx("serialization-runtime-macosx64", "0.20.0"))
}
nativeDarwin()
}
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
org.gradle.jvmargs = -Xmx4g
org.gradle.parallel = true
2 changes: 1 addition & 1 deletion sources/common/Clock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ package io.fluidsonic.time
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith("WallClock", "io.fluidsonic.time.WallClock")
)
typealias Clock = WallClock
public typealias Clock = WallClock
65 changes: 33 additions & 32 deletions sources/common/LocalDate.kt
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
package io.fluidsonic.time

import kotlinx.serialization.*
import kotlinx.serialization.encoding.*
import kotlin.math.*


@Serializable(with = LocalDateSerializer::class)
class LocalDate private constructor(
val year: Year,
val month: MonthOfYear,
val day: DayOfMonth
public class LocalDate private constructor(
public val year: Year,
public val month: MonthOfYear,
public val day: DayOfMonth
) : Comparable<LocalDate> {

init {
freeze()
}


fun atTime(hour: Long, minute: Long = 0, second: Long = 0, nanosecond: Long = 0) =
public fun atTime(hour: Long, minute: Long = 0, second: Long = 0, nanosecond: Long = 0): LocalDateTime =
atTime(HourOfDay.of(hour), MinuteOfHour.of(minute), SecondOfMinute.of(second), NanosecondOfSecond.of(nanosecond))


fun atTime(
public fun atTime(
hour: HourOfDay,
minute: MinuteOfHour = MinuteOfHour(0),
second: SecondOfMinute = SecondOfMinute(0),
nanosecond: NanosecondOfSecond = NanosecondOfSecond(0)
) =
): LocalDateTime =
atTime(LocalTime.of(hour, minute, second, nanosecond))


fun atTime(time: LocalTime) =
public fun atTime(time: LocalTime): LocalDateTime =
LocalDateTime.of(this, time)


Expand All @@ -45,7 +46,7 @@ class LocalDate private constructor(
}


override fun equals(other: Any?) =
override fun equals(other: Any?): Boolean =
this === other || (
other is LocalDate
&& day == other.day
Expand All @@ -54,23 +55,23 @@ class LocalDate private constructor(
)


override fun hashCode() =
override fun hashCode(): Int =
day.hashCode() xor month.hashCode() xor year.hashCode()


fun periodSince(other: LocalDate) =
public fun periodSince(other: LocalDate): Period =
Period.between(other, this)


fun periodUntil(other: LocalDate) =
public fun periodUntil(other: LocalDate): Period =
other.periodSince(this)


override fun toString() =
override fun toString(): String =
buildString(capacity = 10) { toString(this) }


fun toString(builder: StringBuilder) {
public fun toString(builder: StringBuilder) {
with(builder) {
when {
year.toLong() < 0 -> append('-')
Expand Down Expand Up @@ -100,33 +101,33 @@ class LocalDate private constructor(
}


companion object {
public companion object {

private val iso8601Regex = Regex("([+-]?)(\\d{4,10})-(\\d{2})-(\\d{2})")

val firstIn1970 = unchecked(year = 1970, month = 1, day = 1)
public val firstIn1970: LocalDate = unchecked(year = 1970, month = 1, day = 1)


fun now(clock: WallClock = WallClock.systemUtc) =
public fun now(clock: WallClock = WallClock.systemUtc): LocalDate =
clock.localDate()


fun now(timeZone: TimeZone) =
public fun now(timeZone: TimeZone): LocalDate =
now(clock = WallClock.system(timeZone))


fun of(year: Long, month: Long, day: Long) =
public fun of(year: Long, month: Long, day: Long): LocalDate =
of(Year.of(year), MonthOfYear.of(month), DayOfMonth.of(day))


fun of(year: Year, month: MonthOfYear, day: DayOfMonth): LocalDate {
public fun of(year: Year, month: MonthOfYear, day: DayOfMonth): LocalDate {
require(day <= month.lastDayIn(year)) { "'$day' is not a valid day in '${month.name} $year'" }

return unchecked(year, month, day)
}


fun parse(text: CharSequence): LocalDate? {
public fun parse(text: CharSequence): LocalDate? {
val result = iso8601Regex.matchEntire(text) ?: return null

val sign = result.groupValues[1]
Expand Down Expand Up @@ -155,26 +156,26 @@ class LocalDate private constructor(
}


expect fun LocalDate.atStartOfDay(timeZone: TimeZone): Timestamp
expect fun LocalDate.daysSince(startExclusive: LocalDate): Days
expect fun LocalDate.daysUntil(endExclusive: LocalDate): Days
expect fun LocalDate.toDayOfWeek(): DayOfWeek
public expect fun LocalDate.atStartOfDay(timeZone: TimeZone): Timestamp
public expect fun LocalDate.daysSince(startExclusive: LocalDate): Days
public expect fun LocalDate.daysUntil(endExclusive: LocalDate): Days
public expect fun LocalDate.toDayOfWeek(): DayOfWeek

operator fun LocalDate.minus(days: Days) =
public operator fun LocalDate.minus(days: Days): LocalDate =
this + -days

operator fun LocalDate.minus(months: Months) =
public operator fun LocalDate.minus(months: Months): LocalDate =
this + -months

operator fun LocalDate.minus(years: Years) =
public operator fun LocalDate.minus(years: Years): LocalDate =
this + -years

expect operator fun LocalDate.plus(days: Days): LocalDate
expect operator fun LocalDate.plus(months: Months): LocalDate
expect operator fun LocalDate.plus(years: Years): LocalDate
public expect operator fun LocalDate.plus(days: Days): LocalDate
public expect operator fun LocalDate.plus(months: Months): LocalDate
public expect operator fun LocalDate.plus(years: Years): LocalDate


fun LocalDate.atStartOfDay() =
public fun LocalDate.atStartOfDay(): LocalDateTime =
atTime(LocalTime.midnight)


Expand Down
Loading

0 comments on commit 6e2c838

Please sign in to comment.