nodatime

Deserializing Noda Time's LocalDateTime with JSON.NET

这一生的挚爱 提交于 2019-12-10 12:44:25
问题 I'm trying to use Json.NET to serialize some Noda Time values and having trouble. Serialization is simple enough: LocalDateTime dt = ... // Assigned elsewhere LocalDateTimePattern isoDateTimePattern = LocalDateTimePattern.GeneralIsoPattern; JObject root = new JObject(); root.Add("time", isoDateTimePattern.Format(dt)); // Serialize other elements using (var sw = new StreamWriter(stream)) { serializer.Serialize(sw, root); } But deserialization is problematic. Json.NET seems to recognize the ISO

What is the neatest way to find the last possible instant of a LocalDate, in a particular time-zone?

て烟熏妆下的殇ゞ 提交于 2019-12-10 12:43:36
问题 Apologies if this seems a simple question, but I mostly just want to check that the solution I have is the most sensible/holds for all cases. The pre-existing SQL Server database we work with stores a 'period' as inclusive start -> inclusive end UTC DateTime values. (Both start & end columns are datetime2(7) , automatically-converted to System.DateTime instances of DateTimeKind.UTC before we start working with them). So, if I need to store the "whole day/month/year, given the user's time-zone

Deserialize a date query parameter of the form yyyy-MM-dd into a noda time LocalDate object using ASP.NET Web API

旧时模样 提交于 2019-12-09 15:57:00
问题 I'm investigating the use of NodaTime LocalDate to replace our existing use of of the BCL DateTime/DateTimeOffset classes. We have run into a number of timezone related issues with our code due to our misunderstanding of the arguably ambiguous behavior of DateTime. To fully leverage NodaTime I want to be able to send and receive dates from our ASP.NET Web API 2 web services of the form YYYY-MM-DD. I have had success in properly serializing LocalDate to YYYY-MM-DD. However I am unable to

DateTime conversions using NodaTime on ASP.Net MVC 3 Razor website. How to?

不问归期 提交于 2019-12-08 06:52:43
问题 I have the Date/Time stored in the database on the London's time zone (not UTC). What I need is to retrieve this Date/Time, convert it to UTC and display considering the user's time zone (which they define when registering to the site - ie: en-GB, en-US, etc). My first question is more related to the MVC structure, as I'm totally new to this (am a WebForms developer) - Where should I put this conversion code/class/helper? Model? ViewModel? The second question is the conversion itself - I've

How can I know the relation between the city and its time zone in NodaTime?

眉间皱痕 提交于 2019-12-08 02:56:27
问题 Currently I'm using NodaTime to get the time zone from country but the problem is if there are multiple time zones in a country. How could I know the list of the cities in that time zone? I need to know do the mapping between these two data. Is it possible with NodaTime? 回答1: The correct way to handle this is as follows: Find latitude and longitude for each location. If these are airports, then consider using the data from OurAirports.com. You might also be interested in OpenFlights, but be

Convert calendars to each other Use NodaTime library

不打扰是莪最后的温柔 提交于 2019-12-08 00:10:49
问题 I use Noda Time to handle DateTime issues, I read almost all of the documents but I have some problem to convert calendars to each other, First, how many calendars are supported by Noda? As CalendarSystem says there is just 4 calendars: a)CopticCalendar / b)GregorianCalendar / c)IslamicCalendar / d)JulianCalendar so how about other calendar systems? I use Persian Calendar aka Jalali Calendar, So is there any way to use this calendar in NodaTime? And how Convert it to Gregorian Calendar? The

DateTime conversions using NodaTime on ASP.Net MVC 3 Razor website. How to?

若如初见. 提交于 2019-12-07 03:58:28
I have the Date/Time stored in the database on the London's time zone (not UTC). What I need is to retrieve this Date/Time, convert it to UTC and display considering the user's time zone (which they define when registering to the site - ie: en-GB, en-US, etc). My first question is more related to the MVC structure, as I'm totally new to this (am a WebForms developer) - Where should I put this conversion code/class/helper? Model? ViewModel? The second question is the conversion itself - I've played around with the NodaTime test project but can't find a proper way to do this conversion. Any help

How to convert the standard Noda Timezone Id's from English to Localized Language?

╄→гoц情女王★ 提交于 2019-12-06 02:33:11
问题 I am currently trying to localize my windowsphone Time App for a few countries. I am using Noda Time as it was extremely easy for a newbie. The problem I am facing that all the Timezone Id's are in standard English and I am searching for a way to get those Id's converted to Local Language strings. One way would be too make Localized strings for each ID in every language. But it seems to be Highly inefficient as there are 500 timezones. Please suggest a way for me to get directly the TimeZone

Noda Time: Period.Between returning incorrect value

ぐ巨炮叔叔 提交于 2019-12-05 16:30:28
I have a trouble with NodaTime lib. My goal: compute Year/Month/Date between two dates. So, here is my test example: private static void Main() { var list = new List<Tuple<DateTime, DateTime>> { new Tuple<DateTime, DateTime>(new DateTime(1980, 1, 1), new DateTime(1983, 12, 31)), new Tuple<DateTime, DateTime>(new DateTime(2009, 1, 1), new DateTime(2015, 01, 23)) }; var totalPeriod = Period.Zero; foreach (var tuple in list) { var dateFrom = tuple.Item1; var dateTo = tuple.Item2; var ld1 = new LocalDate(dateFrom.Year, dateFrom.Month, dateFrom.Day); var ld2 = new LocalDate(dateTo.Year, dateTo

Create a NodaTime LocalDate representing “today”

我是研究僧i 提交于 2019-12-05 13:24:23
问题 What is the recommended way to create a LocalDate instance that represents "today". I was expecting there to be a static "Now" or "Today" property in the LocalDate class, but there isn't. My current approach is to use DateTime.Now: var now = DateTime.Now; LocalDate today = new LocalDate(now.Year, now.Month, now.Day); Is there a better way? 回答1: First recognize that when you say "today", the answer could be different for different people in different parts of the world. Therefore, in order to