Currently I'm using DateTime (with UTC) to store all dates - experience has taught me always to use UTC for any date time values.

I'd like to use DateTimeOffset because it stores in UTC and also has the timezone offset - but this isn't supported as a built-in type.

What is the best way of achieving this. Should I simply encapsulate DateTimeOffset in a wrapper class that derivces from entity

asked Mar 31 '11 at 03:49

RichardHarrison's gravatar image

RichardHarrison
21447


One Answer:

Hello Richard,

Unfortunately, DateTimeOffset type is not yet supported. In order to store DateTime values with UTC I could recommend to try the following pattern:

class MyEntity : Entity {

  [Field]  // Persistent field
  private DateTime DateTimePart { get; set; }

  [Field]  // Persistent field
  private TimeSpan TimeSpanPart { get; set; }

  // Non persistent field
  public DateTimeOffset UTCDate {
    get { return new DateTimeOffset(DateTimePart, TimeSpanPart); }
    set {
      DateTimePart = value.DateTime;
      TimeSpanPart = value.Offset;
    }
  }
}

Hope that helps. Support for DateTimeOffset might appear in the future versions.

answered Mar 31 '11 at 04:13

Dmitri%20Maximov's gravatar image

Dmitri Maximov
22111211

it's not ideal; but a good enough for now workaround.

(Apr 11 '11 at 07:07) RichardHarrison RichardHarrison's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×6
×1

Asked: Mar 31 '11 at 03:49

Seen: 4,417 times

Last updated: Apr 11 '11 at 07:07

powered by OSQA