mirror of https://github.com/abpframework/abp.git
csharpabpc-sharpframeworkblazoraspnet-coredotnet-coreaspnetcorearchitecturesaasdomain-driven-designangularmulti-tenancy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.2 KiB
42 lines
1.2 KiB
using System;
|
|
using Microsoft.Extensions.Options;
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
namespace Volo.Abp.Timing
|
|
{
|
|
public class Clock : IClock, ITransientDependency
|
|
{
|
|
protected ClockOptions Options { get; }
|
|
|
|
public Clock(IOptions<ClockOptions> options)
|
|
{
|
|
Options = options.Value;
|
|
}
|
|
|
|
public virtual DateTime Now => Options.Kind == DateTimeKind.Utc ? DateTime.UtcNow : DateTime.Now;
|
|
|
|
public virtual DateTimeKind Kind => Options.Kind;
|
|
|
|
public virtual bool SupportsMultipleTimezone => Options.Kind == DateTimeKind.Utc;
|
|
|
|
public virtual DateTime Normalize(DateTime dateTime)
|
|
{
|
|
if (Kind == DateTimeKind.Unspecified || Kind == dateTime.Kind)
|
|
{
|
|
return dateTime;
|
|
}
|
|
|
|
if (Kind == DateTimeKind.Local && dateTime.Kind == DateTimeKind.Utc)
|
|
{
|
|
return dateTime.ToLocalTime();
|
|
}
|
|
|
|
if (Kind == DateTimeKind.Utc && dateTime.Kind == DateTimeKind.Local)
|
|
{
|
|
return dateTime.ToUniversalTime();
|
|
}
|
|
|
|
return DateTime.SpecifyKind(dateTime, Kind);
|
|
}
|
|
}
|
|
}
|