• 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
Re: Need localization-proof method of transporting dates.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need localization-proof method of transporting dates.


  • Subject: Re: Need localization-proof method of transporting dates.
  • From: Michael Ash <email@hidden>
  • Date: Tue, 7 Apr 2009 23:54:38 -0400

On Tue, Apr 7, 2009 at 7:57 PM, Graham Cox <email@hidden> wrote:
> I'm doing this, which is the first step in building an NSData representation
> of the various objects, prior to SHA-1 digesting the result. Be good to know
> if this is adequate for system/architecture independence. The intention is
> that the digest only ever sees a little-endian representation of the time
> interval.
>
> @implementation NSDate (GCHash)
>
> - (NSData*)             gc_hash
> {
>        NSSwappedDouble nt = NSSwapHostDoubleToLittle([self
> timeIntervalSinceReferenceDate]);
>        return [NSData dataWithBytes:&nt length:sizeof(NSSwappedDouble)];
> }
>
> @end

If this is also how you store your dates then this is fine. If you
store them in some other way (e.g. asking the system to put them in an
plist) then this is still fine as long as you're using whole numbers
of seconds. If you can store arbitrary fractional values of seconds in
your dates, and you store them in some other way than the above, then
I would be wary: floating point math is inexact, and it's possible
that the conversion to and from the intermediate representation could
end up with a different least-significant bit.

Note that if you manually convert your date to the serialized
representation but it's not the above, then you could simply hash that
intermediate representation directly.

Mike
_______________________________________________

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: Need localization-proof method of transporting dates.
      • From: Graham Cox <email@hidden>
References: 
 >Need localization-proof method of transporting dates. (From: Graham Cox <email@hidden>)
 >Re: Need localization-proof method of transporting dates. (From: Christopher Kane <email@hidden>)
 >Re: Need localization-proof method of transporting dates. (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Simple printing hangs
  • Next by Date: Re: finder file size
  • Previous by thread: Re: Need localization-proof method of transporting dates.
  • Next by thread: Re: Need localization-proof method of transporting dates.
  • Index(es):
    • Date
    • Thread