Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        /// <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));
        }
Esempio n. 4
0
        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");
        }
Esempio n. 5
0
        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");
        }
Esempio n. 6
0
        /// <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));
        }