Skip to content

Commit aa73fd1

Browse files
committed
add locale to timeButton
1 parent 29da70c commit aa73fd1

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

MTMR/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>0.23</string>
20+
<string>0.23.1</string>
2121
<key>CFBundleVersion</key>
22-
<string>275</string>
22+
<string>278</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.utilities</string>
2525
<key>LSMinimumSystemVersion</key>

MTMR/ItemsParsing.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ enum ItemType: Decodable {
344344
case staticButton(title: String)
345345
case appleScriptTitledButton(source: SourceProtocol, refreshInterval: Double)
346346
case shellScriptTitledButton(source: SourceProtocol, refreshInterval: Double)
347-
case timeButton(formatTemplate: String, timeZone: String?)
347+
case timeButton(formatTemplate: String, timeZone: String?, locale: String?)
348348
case battery()
349349
case dock(autoResize: Bool)
350350
case volume()
@@ -374,6 +374,7 @@ enum ItemType: Decodable {
374374
case api_key
375375
case icon_type
376376
case formatTemplate
377+
case locale
377378
case image
378379
case url
379380
case longUrl
@@ -428,7 +429,8 @@ enum ItemType: Decodable {
428429
case .timeButton:
429430
let template = try container.decodeIfPresent(String.self, forKey: .formatTemplate) ?? "HH:mm"
430431
let timeZone = try container.decodeIfPresent(String.self, forKey: .timeZone) ?? nil
431-
self = .timeButton(formatTemplate: template, timeZone: timeZone)
432+
let locale = try container.decodeIfPresent(String.self, forKey: .locale) ?? nil
433+
self = .timeButton(formatTemplate: template, timeZone: timeZone, locale: locale)
432434

433435
case .battery:
434436
self = .battery()

MTMR/TouchBarController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension ItemType {
2525
return "com.toxblh.mtmr.appleScriptButton."
2626
case .shellScriptTitledButton(source: _):
2727
return "com.toxblh.mtmr.shellScriptButton."
28-
case .timeButton(formatTemplate: _, timeZone: _):
28+
case .timeButton(formatTemplate: _, timeZone: _, locale: _):
2929
return "com.toxblh.mtmr.timeButton."
3030
case .battery():
3131
return "com.toxblh.mtmr.battery."
@@ -255,8 +255,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
255255
barItem = AppleScriptTouchBarItem(identifier: identifier, source: source, interval: interval)
256256
case let .shellScriptTitledButton(source: source, refreshInterval: interval):
257257
barItem = ShellScriptTouchBarItem(identifier: identifier, source: source, interval: interval)
258-
case let .timeButton(formatTemplate: template, timeZone: timeZone):
259-
barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template, timeZone: timeZone)
258+
case let .timeButton(formatTemplate: template, timeZone: timeZone, locale: locale):
259+
barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template, timeZone: timeZone, locale: locale)
260260
case .battery():
261261
barItem = BatteryBarItem(identifier: identifier)
262262
case let .dock(autoResize: autoResize):

MTMR/Widgets/TimeTouchBarItem.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ class TimeTouchBarItem: CustomButtonTouchBarItem {
44
private let dateFormatter = DateFormatter()
55
private var timer: Timer!
66

7-
init(identifier: NSTouchBarItem.Identifier, formatTemplate: String, timeZone: String? = nil) {
7+
init(identifier: NSTouchBarItem.Identifier, formatTemplate: String, timeZone: String? = nil, locale: String? = nil) {
88
dateFormatter.dateFormat = formatTemplate
9+
if let locale = locale {
10+
dateFormatter.locale = Locale(identifier: locale)
11+
}
912
if let abbr = timeZone {
1013
dateFormatter.timeZone = TimeZone(abbreviation: abbr)
1114
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,14 @@ To close a group, use the button:
196196
#### `timeButton`
197197

198198
> Attention! Works not all: https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations
199+
> formatTemplate examples: https://www.datetimeformatter.com/how-to-format-date-time-in-swift/
200+
> locale examples: https://gist.github.com/jacobbubu/1836273
199201
200202
```js
201203
{
202204
"type": "timeButton",
203205
"formatTemplate": "dd HH:mm",
206+
"locale": "en_GB",
204207
"timeZone": "UTC"
205208
}
206209
```

0 commit comments

Comments
 (0)