C# Class Composable.System.DateTimeExtensions

Show file Open project: mlidbom/Composable.Monolithic

Public Methods

Method Description
AssertHasDeterministicValue ( this @this ) : void

Throws an exception if @this.Kind == DateTimeKind.Unspecified.

SafeToLocalTime ( this @this ) : System.DateTime

Like DateTime.ToLocalTime except it will throw an exception if @this.Kind == DateTimeKind.Unspecified instead of assuming that Kind == DateTimeKind.Utc and converting based on that assumption like DateTime.ToLocalTime does.

SafeToUniversalTime ( this @this ) : System.DateTime

Like DateTime.ToUniversalTime except it will throw an exception if @this.Kind == DateTimeKind.Unspecified instead of assuming that Kind == DateTimeKind.Local and converting based on that assumption like DateTime.ToUniversalTime does.

Private Methods

Method Description
HasDeterministicValue ( this @this ) : bool

True if @this.Kind != DateTimeKind.Unspecified. If Kind is Unspecified it is not really possible to know which time this represents. It is not possible to schedule an event to take place at this time etc. In order to be able to do so you must know the timezone for a datetime which you only know if it is not Unspecified.

Method Details

AssertHasDeterministicValue() public static method

Throws an exception if @this.Kind == DateTimeKind.Unspecified.
public static AssertHasDeterministicValue ( this @this ) : void
@this this
return void

SafeToLocalTime() public static method

Like DateTime.ToLocalTime except it will throw an exception if @this.Kind == DateTimeKind.Unspecified instead of assuming that Kind == DateTimeKind.Utc and converting based on that assumption like DateTime.ToLocalTime does.
public static SafeToLocalTime ( this @this ) : System.DateTime
@this this
return System.DateTime

SafeToUniversalTime() public static method

Like DateTime.ToUniversalTime except it will throw an exception if @this.Kind == DateTimeKind.Unspecified instead of assuming that Kind == DateTimeKind.Local and converting based on that assumption like DateTime.ToUniversalTime does.
public static SafeToUniversalTime ( this @this ) : System.DateTime
@this this
return System.DateTime