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

System default locale #1658

Merged
merged 3 commits into from
Nov 9, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package net.mamoe.mirai.internal.utils

import net.mamoe.mirai.utils.*
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.*

Expand Down Expand Up @@ -102,7 +101,9 @@ internal open class StdoutLogger constructor(
else debug(message.toString())
}

protected open val timeFormat: DateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.SIMPLIFIED_CHINESE)
protected open val timeFormat: SimpleDateFormat by threadLocal {
SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
}

private val currentTimeFormatted get() = timeFormat.format(Date())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ package net.mamoe.mirai.utils

import java.text.DateFormat
import java.text.SimpleDateFormat
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.*

/**
Expand Down Expand Up @@ -106,9 +108,12 @@ public actual open class PlatformLogger constructor( // same as StdoutLogger bu
else debug(message.toString())
}

@Deprecated("Use formatter instead.", level = DeprecationLevel.HIDDEN)
protected open val timeFormat: DateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.SIMPLIFIED_CHINESE)

private val currentTimeFormatted get() = timeFormat.format(Date())
protected open val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")

private val currentTimeFormatted get() = formatter.format(LocalDateTime.now())

@MiraiExperimentalApi("This is subject to change.")
protected enum class Color(private val format: String) {
Expand Down
21 changes: 21 additions & 0 deletions mirai-core-utils/src/commonMain/kotlin/ThreadLocal.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2019-2021 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/

package net.mamoe.mirai.utils

import kotlin.reflect.KProperty


public fun <T : Any?> threadLocal(newInstance: () -> T): ThreadLocal<T> {
return object : ThreadLocal<T>() {
override fun initialValue(): T = newInstance()
}
}

public operator fun <T> ThreadLocal<T>.getValue(t: Any?, property: KProperty<Any?>): T = this.get()