protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder .HasDefaultSchema("Identity") .Ignore <DomainEvent>() .ApplyConfiguration(new EventPublishedConfiguration()) .ApplyConfiguration(new EventSubscribedConfiguration()) .ApplyConfiguration(new UserConfiguration()) .ApplyConfiguration(new RoleConfiguration()) .ApplyConfiguration(new PermissionConfiguration()) .ApplyConfiguration(new UserRoleConfiguration()) .ApplyConfiguration(new UserRefreshTokenConfiguration()) .ApplyConfiguration(new RolePermissionConfiguration()); var utcDateTimeConverter = new UtcDateTimeConverter(); var dateTimeProperties = modelBuilder.Model .GetEntityTypes() .SelectMany(x => x.GetProperties()) .Where(x => x.ClrType == typeof(DateTime)); foreach (var property in dateTimeProperties) { property.SetValueConverter(utcDateTimeConverter); } }
public async Task UpdateOwner(Owner dbOwner, Owner owner) { dbOwner.Map(owner); UtcDateTimeConverter.Convert(owner); var sql = "UPDATE [dbo].[Owner] SET Address=@Address, DateOfBirth=@DateOfBirth, Name=@Name WHERE OwnerId = @OwnerId"; await Execute(sql, new { OwnerId = dbOwner.Id, dbOwner.Name, dbOwner.DateOfBirth, dbOwner.Address }, CommandType.Text); }
public async Task CreateOwner(Owner owner) { owner.Id = Guid.NewGuid(); UtcDateTimeConverter.Convert(owner); var sql = "INSERT INTO [dbo].[Owner] VALUES (@OwnerId, @Name, @DateOfBirth, @Address)"; await Execute(sql, new { OwnerId = owner.Id, owner.Name, owner.DateOfBirth, owner.Address }, CommandType.Text); }
/// <summary> /// Converts the local date time into a UTC time /// </summary> /// <param name="dateTime">The current instance of the date time</param> /// <param name="timeZone">The time zone to convert from</param> /// <returns>The same date time but expressed in UTC time</returns> public static DateTime?ToUtc(this DateTime?dateTime, string timeZone = null) { if (dateTime == null) { return(null); } IDateTimeConverter converter = new UtcDateTimeConverter(timeZone); return(converter.Convert((DateTime)dateTime)); }
protected void WriteGenerator(XmlWriter xw, bool forReadability) { xw.WriteStartElement("Generator"); Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); string product = GetAttribute <AssemblyProductAttribute>(assembly).Product; string version = assembly.GetName().Version.ToString(4); xw.WriteAttributeString("name", typeof(MSBuildLogger).FullName); xw.WriteAttributeString("product", product); xw.WriteAttributeString("version", version); xw.WriteAttributeString("date", UtcDateTimeConverter.ToString(DateTime.UtcNow)); xw.WriteEndElement(); }
public void UtcDateTimeConverter_ConvertToUtc_DateTime_UseCustomTimezone_Success() { const string inputValue = "2016-12-31 15:00"; string outputValue = ""; const string timeZone = "Europe/Brussels"; UtcDateTimeConverter converter = new UtcDateTimeConverter(timeZone); const string exactFormat = "yyyy-MM-dd HH:mm"; if (DateTime.TryParseExact(inputValue, exactFormat, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out DateTime output)) { DateTime convertedDate = converter.Convert(DateTime.SpecifyKind(output, DateTimeKind.Utc)); outputValue = convertedDate.ToString(exactFormat); } Assert.True(outputValue == "2016-12-31 14:00"); }
public void UtcDateTimeConverter_ConvertToUtc_DateTime_UseCurrentTimezone_Success() { Thread.CurrentThread.CurrentCulture = new CultureInfo("nl-BE"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("nl-BE"); const string inputValue = "2016-12-31 15:00"; string outputValue = ""; UtcDateTimeConverter converter = new UtcDateTimeConverter(); const string exactFormat = "yyyy-MM-dd HH:mm"; if (DateTime.TryParseExact(inputValue, exactFormat, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out DateTime output)) { DateTime convertedDate = converter.Convert(DateTime.SpecifyKind(output, DateTimeKind.Utc)); outputValue = convertedDate.ToString(exactFormat); } Assert.True(outputValue == "2016-12-31 16:00"); }
/// <summary> /// Converts the local date time into a UTC time /// </summary> /// <param name="dateTime">The current instance of the date time</param> /// <param name="timeZone">The time zone to convert from</param> /// <returns>The same date time but expressed in UTC time</returns> public static DateTime ToUtc(this DateTime dateTime, string timeZone = null) { IDateTimeConverter converter = new UtcDateTimeConverter(timeZone); return(converter.Convert(dateTime)); }