سؤال

I have a Dynamics CRM system that works across multiple timezones. The users work in their local timezones and I have some services that interact with the entities they create.

All code is done through the SDK Generated early bound entity classes.

For example:

  1. User creates a record with an associated task start and end date in GMT-4 timezone
    • Start Date through UI = 2012/11/23 00:00:00
    • Start Date in DB = 2012/11/22 20:00:00
    • End Date through UI = 2012/11/25 00:00:00
    • End Date in DB = 2012/11/24 20:00:00
  2. Services process that record and create a task with start and end dates - this time the service account is at GMT+1 (BST)
    • Start Date through Code = 2012/11/22 20:00:00
    • Start Date in DB = 2012/11/22 19:00:00
    • End Date through UI = 2012/11/24 20:00:00
    • End Date in DB = 2012/11/24 19:00:00
  3. User looks at created record and sees the task start and end dates are 4 hrs earlier - which when the UI renders it shows as 2012/11/22 23:00:00 where the user was expecting 2012/11/23 00:00:00.

I am seeing issues where when a user creates a record which is used by the services that the date mismatch is causing issues.

So I guess I have a number of questions:

  1. Is the datetime returned by the SDK EarlyBoundEntities in Local or UTC (I suspect UTC)?
  2. If its in UTC should my code that updates/creates records also convert the datetime I work on to UTC before setting it (i.e. use datetime.ToLocal() when getting and ToUTC() when setting)?
  3. Should my server adjust for daylight savings or should it stay at a set time i.e. UTC?
هل كانت مفيدة؟

المحلول

  1. Yes, the only time the DateTime is local in CRM is when you are creating a new DateTime in code, and not specifying that it's UTC, or when it is displayed to the user. Anytime CRM stores a `DateTime, if it isn't specified as UTC, it will convert it to UTC based on the user's TimeZone.
  2. Since the SDK is returning it as UTC keep it in that format. Just be aware that if you create a new DateTime, you have to specify that it is UTC (DateTime to UTC ), or else the SDK will convert it to UDC when you save or update it.
  3. This is moot if you always work in UTC.
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top