14

Voice over reads the following NSStrings like so


14:15

"Fourteen fifteen."

This is clearly a time


14:00

"Fourteen."

This is ambiguous.


If the time 14:00 appears in the status bar it correctly reads it as

"Fourteen hundred hours"

How do I achieve this in a localised way?

iOS reading out correct time

Robert
  • 37,670
  • 37
  • 171
  • 213
  • 1
    Have you tried to give UILabel a custom attribute by overriding the `accessibilityLabel` property. Use the appropriate NSDateFormatter with `timeStyle` set to `.MediumStyle` and it should speak out as time. – dirkgroten May 02 '16 at 16:27
  • @dirkgroten - Thanks for the suggestion. Medium style will still produce the text "14:00" right? if so then it will have the same result since the `accessiblityValue` only sees the raw NSString output. – Robert May 02 '16 at 16:59

3 Answers3

3

How do I achieve this in a localised way?

Overriding the accessibilityLabel with the result of NSDateFormatter::localizedStringFromDate() will be the best thing to do because you can only rely upon iOS's own algorithm to handle any language.

The problem of doing it in a localised way is that it will depend on the language you want.

In French, for instance, you will never pronounce the :00, "14:00" will be read as quatorze heures ("fourteen hours"). "14:12" is "quatorze heures douze" (fourteen hours twelve, not "fourteen twelve")

In Spanish, even if reading 24 hours format, you will always read it on a 12 hours basis: "14:00" will be read as las dos de la tarde ("two in the afternoon") not talking about the distinction between "de la tarde" and "de la noche".

In both French or Spanish, you will never say hundred.

Adam
  • 17,838
  • 32
  • 54
  • Good points. There are locale sensitive ways of reading times. This is why it would be hard to write something that converts the string into words i.e. "14:00" -> "Fourteen hundred hours". However, I don't think anything you have suggested will help. The method takes a style (https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/#//apple_ref/doc/c_ref/NSDateFormatterStyle) and will output a string either `14:00` or `2:00 PM`. Voice over only sees the output string, so will still read it "Fourteen" I think. I will give it a go tho. – Robert May 16 '16 at 15:25
1

IMHO it's very easy ;-)

14:00 = Fourteen o'clock

NetVicious
  • 3,848
  • 1
  • 33
  • 47
0
extension Date {
    
    func accessibilityTime() -> String? {
        let dateComponents = Calendar.current.dateComponents([.hour,.minute], from: self)
        let formatter = DateComponentsFormatter()
        formatter.unitsStyle = .spellOut
        return formatter.string(for: dateComponents)
    }
}

this uses the spell-out unit using the DateComponentsFormatter to announce your time in a localised way. It does not fully implement as anyone on the street would say ("a quarter to three" will be announced as "fourteen o'clock and forty-five minutes"*) but it beats the "fourteen forty-five" announcement.

I hope this helps a lot of apps become more accessible for more people. :)

  • I have tried this using my native Dutch Language. For Dutch native speakers ("kwart voor drie" becomes "viertien uur en vijfenveertig minuten")
Lex
  • 166
  • 1
  • 5