Skip to main content

Class DateTimeUtil

Provides utility methods for date and time operations in the Xperiflow system.

Namespace: Workspace.XBR.Xperiflow.Utilities

Assembly: Xperiflow.dll

Declaration
public static class DateTimeUtil

Examples

Converting between UTC and user timezone:

var userTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
var utcTime = DateTime.UtcNow;

// Convert UTC to user timezone
var userTime = DateTimeUtil.GetUserDatetimeFromUTCDatetime(si, utcTime, userTimeZone);

// Convert user timezone back to UTC
var backToUtc = DateTimeUtil.GetUTCDatetimeFromUserDatetime(si, userTime, userTimeZone);

Remarks

The Workspace.XBR.Xperiflow.Utilities.DateTimeUtil class contains static methods for common date and time operations, particularly focusing on timezone conversions between UTC and user-specific timezones. This is essential for maintaining consistent time handling across the Xperiflow system while supporting users in different geographic locations.

Key Features:

  • UTC ConversionConvert between UTC and user-specific timezones

  • Error HandlingComprehensive error handling with OneStream exception patterns

  • Session ContextIntegration with OneStream session information for consistent logging

Usage Guidelines:

All methods require a valid OneStream.Shared.Common.SessionInfo parameter for error handling and logging. Timezone conversions should always be performed through these utility methods to ensure consistency across the application.

Methods

GetUserDatetimeFromUTCDatetime(SessionInfo, DateTime, TimeZoneInfo)

Converts a UTC datetime to the specified user timezone.

Declaration
public static DateTime GetUserDatetimeFromUTCDatetime(SessionInfo si, DateTime UTCDateTime, TimeZoneInfo userTimeZone)
Remarks

This method performs timezone conversion from UTC to a user-specific timezone using the .NET System.TimeZoneInfo.ConvertTimeFromUtc(System.DateTime%2cSystem.TimeZoneInfo) method. The conversion handles daylight saving time transitions automatically.

Returns

System.DateTime

A System.DateTime representing the input time converted to the specified user timezone.

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe session information for error handling and logging
System.DateTimeUTCDateTimeThe UTC datetime to convert
System.TimeZoneInfouserTimeZoneThe target timezone for conversion
Exceptions

System.ArgumentNullException Thrown when si or userTimeZone is null OneStream.Shared.Common.XFException Thrown when an error occurs during timezone conversion

GetUTCDatetimeFromUserDatetime(SessionInfo, DateTime, TimeZoneInfo)

Converts a user timezone datetime to UTC.

Declaration
public static DateTime GetUTCDatetimeFromUserDatetime(SessionInfo si, DateTime UserDateTime, TimeZoneInfo userTimeZone)
Remarks

This method performs timezone conversion from a user-specific timezone to UTC using the .NET System.TimeZoneInfo.ConvertTimeToUtc(System.DateTime) method. The conversion handles daylight saving time transitions automatically and ensures the result is in UTC.

Returns

System.DateTime

A System.DateTime representing the input time converted to UTC.

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosiThe session information for error handling and logging
System.DateTimeUserDateTimeThe datetime in the user's timezone to convert to UTC
System.TimeZoneInfouserTimeZoneThe source timezone of the input datetime
Exceptions

System.ArgumentNullException Thrown when si or userTimeZone is null OneStream.Shared.Common.XFException Thrown when an error occurs during timezone conversion

Inherited Members

  • System.Object.Equals(System.Object)
  • System.Object.Equals(System.Object,System.Object)
  • System.Object.GetHashCode
  • System.Object.GetType
  • System.Object.MemberwiseClone
  • System.Object.ReferenceEquals(System.Object,System.Object)
  • System.Object.ToString

Was this page helpful?