From 0256dffa8a52ce55b7853f2e642ae4cbe3834b7f Mon Sep 17 00:00:00 2001 From: Kevin Peizner Date: Wed, 25 Oct 2023 17:03:33 -0700 Subject: [PATCH] Fix incorrect formatting in NSISO8601DateFormatter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default, the NSISO8601DateFormatter uses the NSISO8601DateFormatWithInternetDateTime formatting: https://github.com/gnustep/libs-base/blob/master/Headers/Foundation/NSISO8601DateFormatter.h#L57 This equates to these format options: ``` NSISO8601DateFormatWithYear | NSISO8601DateFormatWithMonth | NSISO8601DateFormatWithDay | NSISO8601DateFormatWithDashSeparatorInDate | NSISO8601DateFormatWithTime | NSISO8601DateFormatWithColonSeparatorInTime | NSISO8601DateFormatWithTimeZone | NSISO8601DateFormatWithColonSeparatorInTimeZone ``` The last option (`NSISO8601DateFormatWithColonSeparatorInTimeZone`) causes the formatter to append "ZZ:ZZ" to the formatting string. But ZZ maps to a timezone like this: “-0800" according to the ICU documentation: https://unicode-org.github.io/icu/userguide/format_parse/datetime/#date-field-symbol-table The full format string that GNUStep puts together with the above options is: "yyyy-MM-dd'T'HH:mm:ssZZ:ZZ" As a result, "ZZ:ZZ" will always translate to something like: “-0800:-0800” "ZZ:ZZ" should be "ZZZZZ" which is would output the timezone offset once with the `:` separator between hours and minutes. "yyyy-MM-dd'T'HH:mm:ssZZZZZ" is also the same format string used in Apple's implementation according to their documentation: https://developer.apple.com/documentation/foundation/nsiso8601dateformatter/1643114-init --- Source/NSISO8601DateFormatter.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/NSISO8601DateFormatter.m b/Source/NSISO8601DateFormatter.m index 6d51afec6f..5d711e92c7 100644 --- a/Source/NSISO8601DateFormatter.m +++ b/Source/NSISO8601DateFormatter.m @@ -122,7 +122,7 @@ - (NSString *) _buildFormatWithOptions { if (_formatOptions & NSISO8601DateFormatWithColonSeparatorInTimeZone) { - result = [result stringByAppendingString: @"ZZ:ZZ"]; + result = [result stringByAppendingString: @"ZZZZZ"]; } else {