Skip to content

Commit 84fb165

Browse files
committed
attempt to show locale when using default values for showRequiredDate
1 parent ccc1d29 commit 84fb165

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Requires macOS 12.0 and higher.
1313
- Ex: Device is on 14.3 and needing to go to 14.5.
1414
- While 14.4.1 -> 14.5 are not under active exploit, 14.4 contains fixes for 14.3 that were under active exploit.
1515
- Addresses [610](https://github.com/macadmins/nudge/issues/610) and [613](https://github.com/macadmins/nudge/issues/613)
16+
- When `showRequiredDate` is set to `True` and the admin is using the default values for `requiredInstallationDisplayFormat`, Nudge will attempt to understand the current locale and display the menu item appropriately.
17+
- Addresses [615](https://github.com/macadmins/nudge/issues/615)
1618

1719
## [2.0.4] - 2024-07-23
1820
Requires macOS 12.0 and higher.

Nudge/Utilities/Utils.swift

+14-4
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,20 @@ struct DateManager {
553553
return formatter
554554
}()
555555

556-
func coerceDateToString(date: Date, formatterString: String) -> String {
557-
let formatter = DateFormatter()
558-
formatter.dateFormat = formatterString
559-
return formatter.string(from: date)
556+
func coerceDateToString(date: Date, formatterString: String, locale: Locale? = nil) -> String {
557+
if formatterString == "MM/dd/yyyy" {
558+
// Use the specified locale or the current locale if none is provided
559+
let dateFormatter = DateFormatter()
560+
dateFormatter.dateStyle = .short
561+
dateFormatter.timeStyle = .none
562+
dateFormatter.locale = locale ?? Locale.current
563+
return dateFormatter.string(from: date)
564+
} else {
565+
let formatter = DateFormatter()
566+
formatter.dateFormat = formatterString
567+
formatter.locale = locale ?? Locale.current
568+
return formatter.string(from: date)
569+
}
560570
}
561571

562572
func coerceStringToDate(dateString: String) -> Date {

0 commit comments

Comments
 (0)