Wednesday, April 14, 2021 [Tweets] [Favorites]

Big Sur Has Changed How macOS Formats Time

Howard Oakley:

A number of those using my free utilities Ulbow, Mints and T2M2, and possibly others, have recently noticed a bug which prevents them from obtaining any log extracts. When you try to get a log extract or, in T2M2, to run a check on Time Machine, you are shown an error dialog reporting that

log command returned an error number 64

[…]

The reason for this occurring is that, contrary to the scant documentation which Apple provides, when the system clock is set to display time using a 12-hour clock rather than 24-hours, log show now formats all its timestamp fields (field 0, timestamp) using a 12-hour clock and AM/PM as appropriate.

I have no earthly idea what possessed Apple to make this change, nor why it hasn’t made this clear in its release notes. However, if you parse or analyse log entry timestamps, it breaks that completely.

Howard Oakley:

Formatting like yyyy-MM-dd HH:mm:ss isn’t defined by Apple, but conforms to Report TR35 from the Unicode Consortium, and is exhaustively defined here. That makes it clear that setting the hour using HH returns the hour in 24-hour format, ranging from 00 to 23.

Yet when a Mac is set to use 12-hour format, that rule is broken: the hour is returned in h format rather than HH, as unpadded digits between 0 and 11, or maybe even 1 and 12. Furthermore, the am/pm value is being added to the string.

[…]

Sure enough, adding the line dateFormatter.locale = Locale(identifier: "en_US_POSIX") to my code restores respect for my formatting.

Howard Oakley:

The advice given is vague and raises more questions:

“if you’re working with fixed-format dates, you should first set the locale of the date formatter to something appropriate for your fixed format. In most cases the best locale to choose is “en_US_POSIX”, a locale that’s specifically designed to yield US English results regardless of both user and system preferences.”

How do we tell if our specific case is one of those “most cases”? What other effects might that setting have? If someone has set their Mac to run in Danish, should we be using something other than a US English setting here? But above all, why on earth would Apple change “in unexpected ways” a fixed format to something unspecified of its own invention which flies in the face of Report TR35? Just why is it impossible to follow the prescribed format string?

Previously:

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment