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 May 14, 2021
1 parent df318e9 commit 1cc2e50
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ data class PatternDateFormat @JvmOverloads constructor(
}

fun withLocale(locale: KlockLocale?) = this.copy(locale = locale)
fun withTimezoneNames(tzNames: TimezoneNames) = this.copy(tzNames = this.tzNames + tzNames)
fun withTimezoneNames(tzNames: TimezoneNames) = this.copy(tzNames = this.tzNames + tzNames)
fun withOptions(options: Options) = this.copy(options = options)
fun withOptional() = this.copy(options = options.copy(optionalSupport = true))
fun withNonOptional() = this.copy(options = options.copy(optionalSupport = false))

private val openOffsets = LinkedHashMap<Int, Int>()
private val closeOffsets = LinkedHashMap<Int, Int>()

internal val chunks = arrayListOf<String>().also { chunks ->
internal val chunks = arrayListOf<String>().also { chunks ->
val s = MicroStrReader(format)
while (s.hasMore) {
if (s.peekChar() == '\'') {
Expand All @@ -62,7 +62,7 @@ data class PatternDateFormat @JvmOverloads constructor(
}
}.toList()

internal val regexChunks = chunks.map {
internal val regexChunks = chunks.map {
when (it) {
"E", "EE", "EEE", "EEEE", "EEEEE", "EEEEEE" -> """(\w+)"""
"z", "zzz" -> """([\w\s\-+:]+)"""
Expand Down Expand Up @@ -104,8 +104,8 @@ data class PatternDateFormat @JvmOverloads constructor(
}
}

//val escapedFormat = Regex.escape(format)
internal val rx2: Regex = Regex("^" + regexChunks.mapIndexed { index, it ->
//val escapedFormat = Regex.escape(format)
internal val rx2: Regex = Regex("^" + regexChunks.mapIndexed { index, it ->
if (options.optionalSupport) {
val opens = openOffsets.getOrElse(index) { 0 }
val closes = closeOffsets.getOrElse(index) { 0 }
Expand All @@ -120,7 +120,7 @@ data class PatternDateFormat @JvmOverloads constructor(
}.joinToString("") + "$")


// EEE, dd MMM yyyy HH:mm:ss z -- > Sun, 06 Nov 1994 08:49:37 GMT
// EEE, dd MMM yyyy HH:mm:ss z -- > Sun, 06 Nov 1994 08:49:37 GMT
// YYYY-MM-dd HH:mm:ss

override fun format(dd: DateTimeTz): String {
Expand Down Expand Up @@ -180,9 +180,9 @@ data class PatternDateFormat @JvmOverloads constructor(
}
"a" -> if (utc.hours < 12) "am" else "pm"
else -> when {
name.startsWith('\'') -> name.substring(1, name.length - 1)
else -> name
}
name.startsWith('\'') -> name.substring(1, name.length - 1)
else -> name
}
}
}
return out
Expand Down

0 comments on commit 1cc2e50

Please sign in to comment.