3

We have multilingual site, which has content editors from around the world.

We have a maintenance banner on home page which display "Site will be down from dd:mm:yyyy time to this dd:mm:yyyy". This banner should be content manageable. That means content editors can pick From Date and To Date in sitecore to display/hide this banner.

My question is, how does sitecore date time field deal with time zones?

Example scenario:

  • In fr-FR sitecore Item version, If a content editor from France added from date today 9 AM To today 12PM.
  • In en-GB sitecore item version, if a content editor from London added From date today 9AM To today 12PM.

Does below code, displays banner from 9AM to 12PM in french site at french local time and 9AM to 12PM in GB site at GB local time?

@{ if (ShowBroadcastMessageFrom >= DateTime.UtcNow && ShowBroadcastMessageTo <= DateTime.UtcNow)
    {
        //Show maintenance banner
    }
}

If not, what's the best way to achieve this?

1
  • And let's not forget that the UTC format storage is purely a 8.x thing. We don't know which version of Sitecore the OP uses. Commented Jan 29, 2017 at 17:06

3 Answers 3

4

From a purely technical perspective, locales and cultures have no bearing on timezones (i.e., en-US does not mean or even imply the EST time zone, or any other time zone). This is not a Sitecore specific detail.

Inside the CMS, dates are displayed and take input based on the ServerTimeZone setting. However, all dates are stored inside the database as UTC and retrieved as UTC.

The language version of an item has no bearing on what time zone the date/time field is using for input. If you want the ability to set specific time zones on date fields, you'll need to use a custom field such as this one: DateTimeZoneField

1

As @JustinLaster said, dates are stored in and retrieved from the database in UTC. This ensures that all stored dates are location-agnostic (universal), and inherently means that it is the responsibility of the Sitecore Client and end-user application(s) to control how dates should be presented to authors and end-users.

As @JustinLaster also mentioned, the Sitecore uses the ServerTimeZone setting to determine what timezone to convert the UTC dates to when displaying a date to an author. This does, however, mean that it is the responsibility of the developer to ensure that dates and times are displayed in the correct timezones to end-users on the front-end site. You can read Sitecore's official DateTime best practices documentation for more on how best to control this.

For your use-case, specifically, it sounds like you are concerned with ensuring that the date/time that the authors enter is properly converted into universal time, so that the time-range displayed on your maintenance banner is accurate regardless of the end-user's timezone. This could be a bit more of a challenge, and may require some more manual intervention on the part of the content author to specify the dates/times in the Sitecore fields in the same timezone as was set for the ServerTimeZone setting.

1

@Zachary Knievel and @Justin Laster have answered the timezone question (i.e. input is for the server, stored in database as UTC). You will not see 'local time' on your banner, you will instead see whatever time you output in your 'show maintenance banner' block.

When I have faced this scenario and wanted to have different date/time for different languages, I have actually implemented language-specific text fields for the user to type out what they want to show for their language, and also provided them with the 'absolute' field for use with the logical calculation. This provides ultimate customization over the output message and deals with language-specific variants on output easily by putting the output formatting on the author (french and english, for example, do not generally use the same date output format)

Alternatively, you can use a single field and make sure you have help text defined on the field definition so the author knows what timezone they are specifying. You will then have to make sure you output something in the text so that the visitor knows what timezone the date/time displayed is in.

Unless you can absolutely guarantee your visitors are in specific time zones if they want to read your site in a specific language, I would not generally tie time zones to the language. For example, somebody in France might want to read the site in English, but that doesn't mean you should change their timezone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.