Skip to content

Commit

Permalink
attempt to show locale when using default values for showRequiredDate
Browse files Browse the repository at this point in the history
  • Loading branch information
erikng committed Jul 24, 2024
1 parent ccc1d29 commit 84fb165
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Requires macOS 12.0 and higher.
- Ex: Device is on 14.3 and needing to go to 14.5.
- While 14.4.1 -> 14.5 are not under active exploit, 14.4 contains fixes for 14.3 that were under active exploit.
- Addresses [610](https://github.com/macadmins/nudge/issues/610) and [613](https://github.com/macadmins/nudge/issues/613)
- 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.
- Addresses [615](https://github.com/macadmins/nudge/issues/615)

## [2.0.4] - 2024-07-23
Requires macOS 12.0 and higher.
Expand Down
18 changes: 14 additions & 4 deletions Nudge/Utilities/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,20 @@ struct DateManager {
return formatter
}()

func coerceDateToString(date: Date, formatterString: String) -> String {
let formatter = DateFormatter()
formatter.dateFormat = formatterString
return formatter.string(from: date)
func coerceDateToString(date: Date, formatterString: String, locale: Locale? = nil) -> String {
if formatterString == "MM/dd/yyyy" {
// Use the specified locale or the current locale if none is provided
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .short
dateFormatter.timeStyle = .none
dateFormatter.locale = locale ?? Locale.current
return dateFormatter.string(from: date)
} else {
let formatter = DateFormatter()
formatter.dateFormat = formatterString
formatter.locale = locale ?? Locale.current
return formatter.string(from: date)
}
}

func coerceStringToDate(dateString: String) -> Date {
Expand Down

0 comments on commit 84fb165

Please sign in to comment.