Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Commit

Permalink
Sync from next
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Jan 12, 2022
1 parent be84957 commit 0f837f0
Show file tree
Hide file tree
Showing 20 changed files with 388 additions and 326 deletions.
104 changes: 62 additions & 42 deletions .github/workflows/DEPLOY.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,69 @@
name: DEPLOY

on:
push:
tags:
- 'v*'
push:
tags:
- 'v*'

env:
FORCED_VERSION: ${{ github.ref }}
BINTRAY_USER: ${{ secrets.BINTRAY_USER }}
BINTRAY_KEY: ${{ secrets.BINTRAY_KEY }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPEUSERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPEPASSWORD }}
FORCED_VERSION: ${{ github.ref }}
BINTRAY_USER: ${{ secrets.BINTRAY_USER }}
BINTRAY_KEY: ${{ secrets.BINTRAY_KEY }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPEUSERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPEPASSWORD }}

jobs:
publish-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- run: CALL gradlew.bat --no-daemon
shell: cmd
- run: CALL gradlew.bat --no-daemon assemble check publishMingwX64PublicationToMavenRepository
shell: cmd
env:
DISABLE_JAVASCRIPT_TEST: true
publish-mac:
runs-on: macos-latest
steps:
- uses: actions/checkout@v1
- run: ./gradlew
- run: ./gradlew assemble check publish -x publishKotlinMultiplatformPublicationToMavenRepository
env:
DISABLE_JAVASCRIPT_TEST: true
publish-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: sudo apt-get install xvfb
- run: xvfb-run --auto-servernum ./gradlew --no-daemon
- run: xvfb-run --auto-servernum ./gradlew --no-daemon assemble check lint testDebugUnitTest publishKotlinMultiplatformPublicationToMavenRepository publishLinuxX64PublicationToMavenRepository publishLinuxArm64PublicationToMavenRepository publishLinuxArm32HfpPublicationToMavenRepository

publish-finalize:
needs: [publish-windows, publish-mac, publish-linux]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: ./gradlew releaseMavenCentral
publish-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- run: >
CALL gradlew.bat --no-daemon
jvmTest
publishMingwX64PublicationToMavenRepository
shell: cmd
env:
DISABLE_JAVASCRIPT_TEST: true
publish-mac:
runs-on: macos-latest
steps:
- uses: actions/checkout@v1
- run: >
./gradlew
jvmTest
publishMacosX64PublicationToMavenRepository
publishMacosArm64PublicationToMavenRepository
publishIosArm32PublicationToMavenRepository
publishIosArm64PublicationToMavenRepository
publishIosX64PublicationToMavenRepository
publishIosSimulatorArm64PublicationToMavenRepository
publishWatchosX86PublicationToMavenRepository
publishWatchosArm32PublicationToMavenRepository
publishWatchosArm64PublicationToMavenRepository
publishWatchosSimulatorArm64PublicationToMavenRepository
publishTvosX64PublicationToMavenRepository
publishTvosArm64PublicationToMavenRepository
publishTvosSimulatorArm64PublicationToMavenRepository
env:
DISABLE_JAVASCRIPT_TEST: true
publish-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: sudo apt-get install xvfb
- run: >
xvfb-run --auto-servernum ./gradlew --no-daemon
jvmTest
publishKotlinMultiplatformPublicationToMavenRepository
publishJvmPublicationToMavenRepository
publishJsPublicationToMavenRepository
publishAndroidPublicationToMavenRepository
publishLinuxX64PublicationToMavenRepository
publish-finalize:
needs: [publish-windows, publish-mac, publish-linux]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: ./gradlew releaseMavenCentral
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# sytleguide
kotlin.code.style=official

# Kotlin 1.5.20: https://github.com/korlibs/easy-kotlin-mpp-gradle-plugin
easyPluginVersion=0.16.1
# Kotlin 1.6.10: https://github.com/korlibs/easy-kotlin-mpp-gradle-plugin
easyPluginVersion=0.18.2

# version
group=com.soywiz.korlibs.klock
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 3 additions & 1 deletion klock/src/commonMain/kotlin/com/soywiz/klock/DateTime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,9 @@ value class DateTime(
fun toString(format: DateFormat): String = format.format(this)

/** Converts this date to String using the [DateFormat.DEFAULT_FORMAT] for representing it */
override fun toString(): String = DateFormat.DEFAULT_FORMAT.format(this)
fun toStringDefault(): String = DateFormat.DEFAULT_FORMAT.format(this)
//override fun toString(): String = DateFormat.DEFAULT_FORMAT.format(this)
override fun toString(): String = "DateTime($unixMillisLong)"
}

fun max(a: DateTime, b: DateTime): DateTime = DateTime.fromUnix(max(a.unixMillis, b.unixMillis))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ data class DateTimeRange(val from: DateTime, val to: DateTime) : Comparable<Date

fun toString(format: DateFormat): String = "${min.toString(format)}..${max.toString(format)}"
fun toStringLongs(): String = "${min.unixMillisLong}..${max.unixMillisLong}"
override fun toString(): String = toString(DateFormat.FORMAT1)
fun toStringDefault(): String = toString(DateFormat.FORMAT1)
//override fun toString(): String = toString(DateFormat.FORMAT1)
override fun toString(): String = "$min..$max"

override fun compareTo(other: DateTime): Int {
if (this.max <= other) return -1
Expand Down
5 changes: 3 additions & 2 deletions klock/src/commonMain/kotlin/com/soywiz/klock/DateTimeTz.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ class DateTimeTz private constructor(
fun toString(format: DateFormat): String = format.format(this)
/** Converts this date to String using [format] for representing it */
fun toString(format: String): String = DateFormat(format).format(this)

/** Converts this date to String using the [DateFormat.DEFAULT_FORMAT] for representing it */
override fun toString(): String = DateFormat.DEFAULT_FORMAT.format(this)
fun toStringDefault(): String = DateFormat.DEFAULT_FORMAT.format(this)

override fun toString(): String = "DateTimeTz($adjusted, $offset)"
}
49 changes: 25 additions & 24 deletions klock/src/commonMain/kotlin/com/soywiz/klock/KlockLocale.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@ import com.soywiz.klock.internal.substr
import kotlin.native.concurrent.ThreadLocal

@ThreadLocal
private var KlockLocale_default: KlockLocale = KlockLocale.English
private var KlockLocale_default: KlockLocale? = null

abstract class KlockLocale {
abstract val ISO639_1: String
abstract val daysOfWeek: List<String>
abstract val months: List<String>
abstract val firstDayOfWeek: DayOfWeek
// @TODO: This allocates for each get, but Kotlin/Native by lazy or atomic refs are causing issues with this. So let's do this temporarily until a solution is found
open val monthsShort: List<String> by klockLazyOrGet { months.map { it.substr(0, 3) } }
open val daysOfWeekShort: List<String> by klockLazyOrGet { daysOfWeek.map { it.substr(0, 3) } }
open val monthsShort: List<String> get() = months.map { it.substr(0, 3) }
open val daysOfWeekShort: List<String> get() = daysOfWeek.map { it.substr(0, 3) }

private val daysOfWeekWithLocaleList: Array<DayOfWeekWithLocale> = Array(7) { DayOfWeekWithLocale(DayOfWeek[it], this) }
//private val daysOfWeekWithLocaleList: Array<DayOfWeekWithLocale> = Array(7) { DayOfWeekWithLocale(DayOfWeek[it], this) }

fun localizedDayOfWeek(dayOfWeek: DayOfWeek) = daysOfWeekWithLocaleList[dayOfWeek.index0]
//fun localizedDayOfWeek(dayOfWeek: DayOfWeek) = daysOfWeekWithLocaleList[dayOfWeek.index0]
fun localizedDayOfWeek(dayOfWeek: DayOfWeek) = DayOfWeekWithLocale(DayOfWeek[dayOfWeek.index0], this)

val daysOfWeekComparator = Comparator<DayOfWeek> { a, b ->
val daysOfWeekComparator get() = Comparator<DayOfWeek> { a, b ->
a.index0Locale(this).compareTo(b.index0Locale(this))
}

open val ordinals = Array(32) {
open val ordinals get() = Array(32) {
if (it in 11..13) {
"${it}th"
} else {
Expand Down Expand Up @@ -62,7 +63,7 @@ abstract class KlockLocale {
}
*/

open val h12Marker = listOf("AM", "OM")
open val h12Marker get() = listOf("AM", "OM")

// This might be required for some languages like chinese?
open fun intToString(value: Int) = "$value"
Expand All @@ -71,23 +72,23 @@ abstract class KlockLocale {

protected fun format(str: String) = PatternDateFormat(str, this)

open val formatDateTimeMedium = format("MMM d, y h:mm:ss a")
open val formatDateTimeShort = format("M/d/yy h:mm a")
open val formatDateTimeMedium get() = format("MMM d, y h:mm:ss a")
open val formatDateTimeShort get() = format("M/d/yy h:mm a")

open val formatDateFull = format("EEEE, MMMM d, y")
open val formatDateLong = format("MMMM d, y")
open val formatDateMedium = format("MMM d, y")
open val formatDateShort = format("M/d/yy")
open val formatDateFull get() = format("EEEE, MMMM d, y")
open val formatDateLong get() = format("MMMM d, y")
open val formatDateMedium get() = format("MMM d, y")
open val formatDateShort get() = format("M/d/yy")

open val formatTimeMedium = format("HH:mm:ss")
open val formatTimeShort = format("HH:mm")
open val formatTimeMedium get() = format("HH:mm:ss")
open val formatTimeShort get() = format("HH:mm")

companion object {
val english get() = English

var default: KlockLocale
set(value) = run { KlockLocale_default = value }
get() = KlockLocale_default
set(value) { KlockLocale_default = value }
get() = KlockLocale_default ?: English

inline fun <R> setTemporarily(locale: KlockLocale, callback: () -> R): R {
val old = default
Expand All @@ -103,19 +104,19 @@ abstract class KlockLocale {
open class English : KlockLocale() {
companion object : English()

override val ISO639_1 = "en"
override val ISO639_1 get() = "en"

override val firstDayOfWeek: DayOfWeek = DayOfWeek.Sunday
override val firstDayOfWeek: DayOfWeek get() = DayOfWeek.Sunday

override val daysOfWeek: List<String> = listOf(
override val daysOfWeek: List<String> get() = listOf(
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
)
override val months: List<String> = listOf(
override val months: List<String> get() = listOf(
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
)

override val formatTimeMedium = format("h:mm:ss a")
override val formatTimeShort = format("h:mm a")
override val formatTimeMedium get() = format("h:mm:ss a")
override val formatTimeShort get() = format("h:mm a")
}
}
34 changes: 19 additions & 15 deletions klock/src/commonMain/kotlin/com/soywiz/klock/PatternDateFormat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ data class PatternDateFormat @JvmOverloads constructor(
internal val regexChunks = chunks.map {
when (it) {
"E", "EE", "EEE", "EEEE", "EEEEE", "EEEEEE" -> """(\w+)"""
"z", "zzz" -> """([\w\s\-+:]+)"""
"z", "zzz" -> """([\w\s\-\+:]+)"""
"do" -> """(\d{1,2}\w+)"""
"d" -> """(\d{1,2})"""
"dd" -> """(\d{2})"""
Expand Down Expand Up @@ -242,18 +242,14 @@ data class PatternDateFormat @JvmOverloads constructor(
if (doThrow) throw RuntimeException("Zulu Time Zone is only accepted with X-XXX formats.") else return null
}
value.first() != 'Z' -> {
val valueUnsigned = value.drop(1)
val hours = when (name) {
"X", "x" -> valueUnsigned.toInt()
"XX", "xx" -> valueUnsigned.take(2).toInt()
"XXX", "xxx" -> valueUnsigned.substringBefore(':').toInt()
else -> throw RuntimeException("Unreachable code! Incorrect implementation!")
val valueUnsigned = value.replace(":", "").removePrefix("-").removePrefix("+")
val hours = when (name.length) {
1 -> valueUnsigned.toInt()
else -> valueUnsigned.take(2).toInt()
}
val minutes = when (name) {
"X", "x" -> 0
"XX", "xx" -> valueUnsigned.drop(2).toInt()
"XXX", "xxx" -> valueUnsigned.substringAfter(':', "0").toInt()
else -> throw RuntimeException("Unreachable code! Incorrect implementation!")
val minutes = when (name.length) {
1 -> 0
else -> valueUnsigned.drop(2).toInt()
}
offset = hours.hours + minutes.minutes
if (value.first() == '-') {
Expand All @@ -263,15 +259,23 @@ data class PatternDateFormat @JvmOverloads constructor(
}
"MMMM" -> month = realLocale.months.indexOf(value) + 1
"MMMMM" -> if (doThrow) throw RuntimeException("Not possible to get the month from one letter.") else return null
"a" -> isPm = value == "pm"
"a" -> isPm = value.equals("pm", ignoreCase = true)
else -> {
// ...
}
}
}
//return DateTime.createClamped(fullYear, month, day, hour, minute, second)
if (is12HourFormat && isPm) {
hour += 12
if (is12HourFormat) {
if (isPm) {
if (hour != 12) {
hour += 12
}
} else {
if (hour == 12) {
hour = 0
}
}
}
val dateTime = DateTime.createAdjusted(fullYear, month, day, hour, minute, second, millisecond)
return dateTime.toOffsetUnadjusted(offset ?: 0.hours)
Expand Down
2 changes: 1 addition & 1 deletion klock/src/commonMain/kotlin/com/soywiz/klock/Stopwatch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Stopwatch(val nanosecondProvider: () -> Double = { PerformanceCounter.nano
private var running = false
private var nanoseconds = 0.0
private val clock get() = nanosecondProvider()
private fun setStart() = run { nanoseconds = clock }
private fun setStart() { nanoseconds = clock }
init {
setStart()
}
Expand Down
Loading

0 comments on commit 0f837f0

Please sign in to comment.