From 08f631e5850ff8ad5c777f8599117e68f2caf1a9 Mon Sep 17 00:00:00 2001 From: Chris Simpson Date: Sun, 24 May 2020 14:45:16 -0400 Subject: [PATCH] Update date format to use 24hr based on locale. Current implementation uses a blanket `HH` date format (24h) which is incorrect, as many users/locales default to a 12 hour format (`hh`). This fix bases the format on the current locale set, however it would be better to directly check or listen to changes in the system preferences. --- WeatherGroundServer.xm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/WeatherGroundServer.xm b/WeatherGroundServer.xm index 1a00772..6f60bee 100755 --- a/WeatherGroundServer.xm +++ b/WeatherGroundServer.xm @@ -51,8 +51,10 @@ [self changeLabelTextWithAttributedString:temperatureAttrString]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ - NSDateFormatter *formatter = [NSDateFormatter new]; - formatter.dateFormat = @"HH:mm"; + NSString *format = [NSDateFormatter dateFormatFromTemplate:@"j" options:0 locale:[NSLocale currentLocale]]; + BOOL is24Hour = ([format rangeOfString:@"a"].location == NSNotFound); + NSDateFormatter *formatter = [NSDateFormatter new]; + formatter.dateFormat = [NSString stringWithFormat:@"%@:mm", (is24Hour ? "HH" : "hh")]; NSString *currentStatusTime = [formatter stringFromDate:[NSDate now]]; self.statusStringView.attributedText = nil; @@ -248,4 +250,4 @@ return attrString; } -@end \ No newline at end of file +@end