あなたはNHibernateの流暢自動マッピングを使用する場合は、これがために私の慣例だ:私はUtcDateTimeTypeを持続することを好む、それがローカルに変換するよりも、
public class UtcDateTimeConvention : IPropertyConvention, IPropertyConventionAcceptance
{
public void Apply(IPropertyInstance instance)
{
instance.CustomType<UtcDateTimeType>();
}
public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
{
criteria.Expect(x =>
x.Property.PropertyType.Equals(typeof(DateTime)) ||
x.Property.PropertyType.Equals(typeof(DateTime?)));
}
}
:
public static DateTime ToUserTimeZone(this DateTime utcDateTime, TimeZoneInfo currentTimeZone)
{
if (utcDateTime.Kind != DateTimeKind.Utc)
{
throw new ArgumentException("utcDateTime.Kind != DateTimeKind.Utc", "utcDateTime");
}
return TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, currentTimeZone);
}
public static DateTime? ToUserTimeZone(this DateTime? utcDateTime, TimeZoneInfo currentTimeZone)
{
if (utcDateTime.HasValue)
{
return ToUserTimeZone(utcDateTime.Value, currentTimeZone);
}
return null;
}
NHibernateはどのようなオフセットを適用するのか知っていますか?歴史的な日付の読み込みはどのように扱われますか? UTCを採用しようとするならば、コードベース全体に渡る必要があります。 –
説明:**•2000年1月1日以降のティック数を示す62ビットの数値 •DateTimeKind(Unspecified、Local、Utc)**を示す2ビットの列挙型。あなたはいつでも変換を行うことができます –