Azure 中依赖英国夏令时的应用程序出现问题
我要迁移到云端的本地应用程序的一部分,显示来自 json 源的电视调度信息。核心数据使用从开始日期开始的偏移量(以秒为单位)来获取其开始时间,这一切都很好,因为这些都是 int UTC 格式。
问题出现在向云迁移的过程中。
本地应用程序位于英国,因此区域设置为 UntedKingdom,并且使用正确输出电视时间。
return programmeStart.AddHours(programmeStart.IsDaylightSavingTime() ? 1 : 0);
但是,现在已转移到云端,IsDaylightSavingTime 的功能不再返回 true,因为数据中心与 BST 无关。
我一直在绞尽脑汁寻找一种方法来尝试解决这个问题。
是否有一种快速、简单的方法来设置托管服务在 Azure 中运行的区域设置,或者是创建一个扩展方法的最佳解决方案,该方法读取 BST 运行时的边界,然后从那里返回 true 或 false示例
public static class DateTimeExtension
{
public static bool IsMyDaylightSavingTime(this DateTime timeToTest)
{
if(timeToTest >= GetConfig("bstStart") && timeToTest <= GetConfig("bstFinish"))
{
return true;
}
return false;
}
}
并且维护 bst 的配置值随着它们的移动而变化?
谢谢
Part of an on premise app I am moving to the cloud, displays TV Scheduling information from a json source. The core data uses an offset in seconds from a start date to get it's start times which is all fine as these are all int UTC format.
The problem arises in the movement to the cloud.
The on premise app was situated in the UK so the locale is UntedKingdom and the TV times were correctly output using
return programmeStart.AddHours(programmeStart.IsDaylightSavingTime() ? 1 : 0);
However, having now moved to the cloud, the functionality for IsDaylightSavingTime, no longer returns true due to data centers being BST Agnostic.
Been racking my brains for a way to try and sort this.
Is there a quick and easy way to set what locale your hosted service runs under in Azure, or is the best solution to create an extension method that reads the boundries of when BST runs from and to, and then return true or false from there for example
public static class DateTimeExtension
{
public static bool IsMyDaylightSavingTime(this DateTime timeToTest)
{
if(timeToTest >= GetConfig("bstStart") && timeToTest <= GetConfig("bstFinish"))
{
return true;
}
return false;
}
}
And the maintaing the config values of bst changing as they move?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法更改 Azure 服务器的时区 - 有很多事情都假设 UTC 是当前设置。
您应该能够通过字符串获取英国时区信息,例如:
完成此操作后,您可以使用框架方法
TimeZoneInfo.IsDaylightSavingTime
http://msdn.microsoft.com/en-us/library/bb460642.aspxYou can't change the timezone of the Azure servers - there's lots going on that assumes UTC is the current setting.
You should be able to get hold of the UK timezoneinfo by string, e.g.:
After you've done that, then you can use the framework method
TimeZoneInfo.IsDaylightSavingTime
http://msdn.microsoft.com/en-us/library/bb460642.aspx为什么不能简单地返回 UTC 并让客户端根据其区域设置进行翻译?
编辑:这是代码
Why can't you simply return UTC and let the client translate that per their locale?
Edit: Here is code