Re: Locale query
Re: Locale query
- Subject: Re: Locale query
- From: Jonathan Mitchell <email@hidden>
- Date: Thu, 13 Nov 2014 15:51:11 +0000
> On 13 Nov 2014, at 15:23, John Joyce <email@hidden> wrote:
>
>
>> On Nov 13, 2014, at 9:54 PM, Jonathan Mitchell <email@hidden> wrote:
>>
>> I have an app that must process sqlite hosted data that contains Gregorian UTC dates.
>> I want to ignore the local locale entirely and use Gregorian UTC through out.
>>
>> At present I am carefully configuring all my NSDatePickers controls and all NSDateComponents calculations to use a specified Gregorian UTC timezoned calendar.
>>
>> Is this the best I can do, or am I missing a trick somewhere?
>>
>> .NET has the concept of a thread culture that defines this sort of thing for a given thread..
>>
>> Thanks
>>
>> Jonathan
>>
> If you want to present things to users well, it is generally easier for people to think in their own locale.
> Better to calculate than they have to think about the difference.
> If the user story is one where they would actively think in Gregorian UTC, then it could be reasonable to do what you’re doing.
I think this is the case here.
The app performs financial calculations that are valid in one timezone.
If the user locates to a different timezone the apps calculations must still reference the initial timezone.
Failure to do this causes miscalculation.
> There are lots of conveniences added in the 10.9 SDK for calendrical calculation, and in general, it is easier for all to work in NSDate/NSTimeInterval (time since reference date) for calculation and then use locales for presentation.
> In this case you might consider the DB to be another user of sorts that needs its locale to be Gregorian UTC, so your work all happens in the intermediary form and humans and the DB get the locale they like to use.
> If you have the calendar and time zone, the dates are easier to covert to the non-locale form and that is easy to convert to any locale. (and vice versa).
> Or did I misunderstand something?
I don’t think so.
I was running into problems using the local locale (which utilises british summer time) when computing the number of days between dates (I use the NSCalendar category method shown below).
I suppose the question is equivalent to asking if it is possible to configure an individual app to return a predefined NSCalendar instance for [NSCalendar currentCalendar] (I severely doubt this is possible).
This would prevent me from introducing bugs by forgetting to configure my NSDatePicker s correctly etc.
Thanks
Jonathan
- (NSInteger)daysWithinEraFromDate:(NSDate *) startDate toDate:(NSDate *) endDate
{
NSInteger startDay=[self ordinalityOfUnit:NSDayCalendarUnit
inUnit: NSEraCalendarUnit forDate:startDate];
NSInteger endDay=[self ordinalityOfUnit:NSDayCalendarUnit
inUnit: NSEraCalendarUnit forDate:endDate];
// note call ABS() for absolute difference
return endDay-startDay;
}
_______________________________________________
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
References: | |
| >Locale query (From: Jonathan Mitchell <email@hidden>) |