Skip to content

Set time zone to the user's local time zone when using date formatters #1176

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

Merged
merged 1 commit into from
Apr 23, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Sources/Diagnose/DiagnoseCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public struct DiagnoseCommand: AsyncParsableCommand {

for crashInfo in crashInfos {
let dateFormatter = DateFormatter()
dateFormatter.timeZone = NSTimeZone.local
dateFormatter.dateStyle = .none
dateFormatter.timeStyle = .medium
let progressMessagePrefix = "Reducing Swift compiler crash at \(dateFormatter.string(from: crashInfo.date))"
Expand Down Expand Up @@ -304,7 +305,9 @@ public struct DiagnoseCommand: AsyncParsableCommand {

progressBar = PercentProgressAnimation(stream: stderrStream, header: "Diagnosing sourcekit-lsp issues")

let date = ISO8601DateFormatter().string(from: Date()).replacingOccurrences(of: ":", with: "-")
let dateFormatter = ISO8601DateFormatter()
dateFormatter.timeZone = NSTimeZone.local
let date = dateFormatter.string(from: Date()).replacingOccurrences(of: ":", with: "-")
let bundlePath = FileManager.default.temporaryDirectory
.appendingPathComponent("sourcekitd-reproducer-\(date)")
try FileManager.default.createDirectory(at: bundlePath, withIntermediateDirectories: true)
Expand All @@ -330,9 +333,9 @@ public struct DiagnoseCommand: AsyncParsableCommand {
print(
"""

Bundle created.
When filing an issue at https://github.com/apple/sourcekit-lsp/issues/new,
please attach the bundle located at
Bundle created.
When filing an issue at https://github.com/apple/sourcekit-lsp/issues/new,
please attach the bundle located at
\(bundlePath.path)
"""
)
Expand Down
1 change: 1 addition & 0 deletions Sources/Diagnose/SwiftFrontendCrashScraper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct SwiftFrontendCrashScraper {
}
let interestingString = fileContents[firstNewline...]
let dateFormatter = DateFormatter()
dateFormatter.timeZone = NSTimeZone.local
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSSS Z"
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .formatted(dateFormatter)
Expand Down
3 changes: 2 additions & 1 deletion Sources/LSPLogging/NonDarwinLogging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ public struct NonDarwinLogMessage: ExpressibleByStringInterpolation, Expressible
/// a new `DateFormatter` is rather expensive and its the same for all loggers.
private let dateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS"
dateFormatter.timeZone = NSTimeZone.local
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSSS Z"
return dateFormatter
}()

Expand Down