• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Date Formatter relative date formatting
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Date Formatter relative date formatting


  • Subject: Date Formatter relative date formatting
  • From: Daniel Phillips <email@hidden>
  • Date: Fri, 28 Oct 2016 09:05:06 +0100

Hello,

When using NSDateFormatter for relative date formatting, I am getting the localised word for today capitalised in some locales not not all. Is this expected behaviour?  I’ve tried to research this and it seems the word today shouldn’t be capitalised (in English at least...) unless it’s used in a title, if true, then is this a bug in NSDateFormatter?

I want to tell the user something is free until a certain time, in my example I’m always saying it’s free until in 2 minutes time. Consider the following code:

import Foundation

let formatter = DateFormatter()
formatter.timeStyle = .short
formatter.dateStyle = .short
formatter.doesRelativeDateFormatting = true
formatter.locale = Locale(identifier: "en_GB")

"Free until \(formatter.string(from: Date(timeIntervalSinceNow: 120)))"

The problem is that by using doesRelativeDateFormatting on my date formatter, I’m relying on it to get the correct word for yesterday, today or tomorrow. And it seems that in a mix of locales this is capitalised. For example:

en_GB:
Free until Today, 08:52

es_ES:
Free until hoy 8:54

pt_BR:
Free until Hoje, 08:54

fr_FR:
Free until aujourd’hui 08:54


Any ideas and input welcome,

Thanks,
Daniel
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Date Formatter relative date formatting
      • From: Quincey Morris <email@hidden>
    • Re: Date Formatter relative date formatting
      • From: Steve Mills <email@hidden>
  • Prev by Date: Re: CoreData headaches
  • Next by Date: Re: Date Formatter relative date formatting
  • Previous by thread: Re: CoreData headaches
  • Next by thread: Re: Date Formatter relative date formatting
  • Index(es):
    • Date
    • Thread