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

[console] fix: 修复跨年时日志文件名日期错乱问题 #2830

Merged
merged 1 commit into from
Jan 25, 2024

Conversation

Takeoff0518
Copy link
Contributor

#2829

DailySplitLogRecorder 中,日期格式化使用了大写的 YYYY,但正确的应该是小写的 yyyy。因为在 DateTimeFormatter 中,yyyy 表示年份,而 YYYY 表示一周中的年份。在使用大写 YYYY 的情况下,只要本周跨年,那么这周就算入下一年。这导致了在跨年的情况下会出现日志错乱的问题。

一个简单的例子如下:

import java.time.LocalDate
import java.time.format.DateTimeFormatter

fun main() {
    val date = LocalDate.of(2023, 12, 31)
    val formatterYYYY = DateTimeFormatter.ofPattern("YYYY-MM-dd")
    val formatteryyyy = DateTimeFormatter.ofPattern("yyyy-MM-dd")
    println(date.format(formatterYYYY))
    println(date.format(formatteryyyy))
}

输出:

2024-12-31 // 2023 年的最后一天被分配到 2024 周
2023-12-31 // 普通的年,这是正确的

摘自 docs.oracle.com

  Symbol  Meaning                     Presentation      Examples
  ------  -------                     ------------      -------
   y       year-of-era                 year              2004; 04
   Y       week-based-year             year              1996; 96

修正 DailySplitLogRecorder 中日期格式化模式中使用错误的模式字符串的问题。将大写的 "YYYY" 更正为小写的 "yyyy",以确保在跨年时生成的日志文件显示正确的年份。
@Takeoff0518 Takeoff0518 marked this pull request as ready for review January 7, 2024 13:44
@Takeoff0518 Takeoff0518 changed the title fix: 修复日期混淆问题 [console] fix: 修复跨年时日志文件名日期错乱问题 Jan 8, 2024
@Karlatemp Karlatemp added the s:console 子系统: mirai-console label Jan 9, 2024
@Karlatemp Karlatemp added t:problem 类型: 不容易归类为特性或 bug 的综合问题 N 优先级: 一般 z:ready-to-merge 状态: PR 已经可以合并, 正在等待一些安排 labels Jan 9, 2024
@Him188 Him188 merged commit 1253385 into mamoe:dev Jan 25, 2024
1 check passed
@kagg886
Copy link

kagg886 commented Feb 1, 2024

恭喜你发现年度隐藏bug(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
N 优先级: 一般 s:console 子系统: mirai-console t:problem 类型: 不容易归类为特性或 bug 的综合问题 z:ready-to-merge 状态: PR 已经可以合并, 正在等待一些安排
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] mirai日志把2023年12月31日错误命名到了2024年12月31日
4 participants