Last active
December 17, 2015 07:19
-
-
Save Maarten88/5571926 to your computer and use it in GitHub Desktop.
Globalization in ASP.NET cloud applications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Auction.Web.Utility | |
{ | |
public static class DateTimeExtensions | |
{ | |
public static DateTime ToLocalAuctionTime(this DateTime dt) | |
{ | |
// dt.DateTimeKind should be Utc! | |
var tzi = TimeZoneInfo.FindSystemTimeZoneById(AppSettings.TimeZoneId); | |
return TimeZoneInfo.ConvertTimeFromUtc(DateTime.SpecifyKind(dt, DateTimeKind.Utc), tzi); | |
} | |
public static DateTime ToUtcTime(this DateTime dt) | |
{ | |
var tzi = TimeZoneInfo.FindSystemTimeZoneById(AppSettings.TimeZoneId); | |
return TimeZoneInfo.ConvertTimeToUtc(dt, tzi); | |
} | |
public static DateTime RoundDown(this DateTime dateTime, int minutes) | |
{ | |
return new DateTime(dateTime.Year, dateTime.Month, | |
dateTime.Day, dateTime.Hour, (dateTime.Minute / minutes) * minutes, 0); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GetActiveAuction : Query<Auction> | |
{ | |
public override Auction Execute(DbAccess context) | |
{ | |
return context.Query<Auction>("SELECT * FROM Auction WHERE State = @State AND [Start] <= @Now AND [End] >= @Now", new { State = AuctionState.Running, Now = DateTime.UtcNow }).FirstOrDefault(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<appSettings> | |
<add key="TimeZoneId" value="W. Europe Standard Time" /> | |
</appSettings> | |
<system.web> | |
<globalization culture="nl-NL" uiCulture="nl-NL" enableClientBasedCulture="false" requestEncoding="utf-8" responseEncoding="utf-8" /> | |
</system.web> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment