You could subclass NSDatePicker and have the subclass always set the configuration the way you need it. It's just an NSControl, its only designated initializer is initWithFrame:
On Nov 13, 2014, at 7:51 AM, Jonathan Mitchell <[email protected]> wrote: > >> On 13 Nov 2014, at 15:23, John Joyce <[email protected]> wrote: >> >> >>> On Nov 13, 2014, at 9:54 PM, Jonathan Mitchell <[email protected]> >>> 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 protected]) > > 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: > https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.apple.com_mailman_options_cocoa-2Ddev_lrucker-2540vmware.com&d=AAIGaQ&c=Sqcl0Ez6M0X8aeM67LKIiDJAXVeAw-YihVMNtXt-uEs&r=ie7S-J__EKnfyVOBV7-jV2rZ--p47O6vkyTklpDM3h4&m=rb-7yHj8naVe-RF7sBz8ywmbZLNz2KFHjGqsCPkVZQU&s=yz3RBo-JSwPvNr96i0Ev9XdyxDShL8sLsbJ2NJh1VEo&e= > > > This email sent to [email protected] _______________________________________________ Cocoa-dev mailing list ([email protected]) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
