3

I have using buckets to store items, we facing a wired issue that when any item created by 12 AM to 4 AM all the items are created on the previous day folder, but it supposed to be created in the current date. We have hosted the site in Azure VM in UAE, i have tried to update the setting

<setting name="ServerTimeZone" value="" > to point to Arabian Standard Time (UTC+04:00) Abu Dhabi, Muscat

as per this document https://learn.microsoft.com/en-us/previous-versions/windows/embedded/gg154758(v=winembedded.80)?redirectedfrom=MSDN but no luck, the standardvalues for createdate is showing of yesterday date in raw values, I have tried with value to GST timezone but still no luck.

Please let me know is there any way to achieve this apart from customization of the bucket folder structure in c# code or by rules.

enter image description here

2 Answers 2

1

In sitecore, all datetime vales are stored in the databases in UTC format, this is the value you are seeing when viewing as raw values.

When these values are shown within a user interface, the values are converted to the server timezone. This is the config value that you have highlighted in your question. If it is empty, then the timezone of the server operating system is used.

The OTB rule which you are using "create the folder structure based on the creation date of the new bucketable item in yyyy/MM format" uses the UTC version of the date time, which is why you are always seeing results for 4 hours earlier in time.

As far as im aware, there is on way to specify that the rule uses the converted server time value, when calculating the bucketed path.

You will need to create a custom rule, using your own code that converts to server time, prior to setting the folder structure.

Have a look at this article, which customizes the depth of folders. I imagine, you could use it as a starting point to create your own custom rule:

https://sitecorejunkie.com/2016/05/25/customize-how-item-bucket-folder-paths-are-created-using-the-sitecore-rules-engine/

See this page for more info regarding UTC vs Servertime:

https://doc.sitecore.com/xp/en/developers/latest/sitecore-experience-manager/date-time-types.html

UPDATE 24/9/24

Further to your comment, there is currently no way to achieve your goal using config/settings alone. The only OTB bucket action uses the created date, which uses the raw UTC value from the database.

The only other thing that you might consider, would be to change the timezone on the VMs that are running sitecore to UTC (Co-ordinated Universal Time). Then set ServerTimeZone config to match. Beware though, as this may have unintended consequences elsewhere, as dates previously set in the system could appear 4 hours out of sync.

2
  • Thanks, I'm checking to see without using any custom code or rule, as I have already customized the bucket folder structure using the IDynamicBucketFolderPath and it works fine, but Im looking for config level like the sitecore settings.
    – Nelson
    Commented Sep 24 at 13:12
  • It not possible to achieve what you are looking for via config/settings. There is only one OTB action relating to created date and that is in UTC format. The only other option that you could consider would be changing the system time on the server to UTC. Commented Sep 24 at 14:00
0

When the bucket item is created, it follows the UTC timezone to create the folder structure, thats the reason you are getting the item path with the previous date.

In order to address this issue, you will need to create a custom rule as below in order to convert the UTC time to server time while generating the bucket item path.

using Sitecore;
using Sitecore.Buckets.Rules.Bucketing;
using Sitecore.Buckets.Util;
using Sitecore.Diagnostics;
using Sitecore.Rules.Actions;
using System;

public class CreateServerTimeZoneBucketPath<T> : RuleAction<T> where T : BucketingRuleContext
{
  /// <summary>Gets or sets the date format</summary>
  /// <value>The script id.</value>
  public string Format { get; set; }

  /// <summary>Executes the specified rule context.</summary>
  /// <param name="ruleContext">The rule context.</param>
  public override void Apply(T ruleContext)
  {
     Assert.ArgumentNotNull((object)ruleContext, nameof(ruleContext));
     string format = this.Format;
     if (string.IsNullOrEmpty(format))
        format = BucketConfigurationSettings.BucketFolderPath;
     var serverDate = DateUtil.ToServerTime(ruleContext.CreationDate);
     ruleContext.ResolvedPath = serverDate.ToString(format, (IFormatProvider)Context.Culture);
   }
}

This rule then be configured inside /sitecore/system/Settings/Buckets/Item Buckets Settings path to generate the bucket item path as per the server timezone.

enter image description here

Hope this helps!!! Let me know in case you have any queries.

1
  • Thanks, I'm checking to see without using any custom code or rule, as I have already customized the bucket folder structure using the IDynamicBucketFolderPath and it works fine, but Im looking for config level like the sitecore settings.
    – Nelson
    Commented Sep 24 at 13:32

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.