nodatime

Calculate duration (amount to spring forward/fall back) at DST transitions boundaries

半城伤御伤魂 提交于 2021-01-05 07:19:26
问题 From this great answer, I am able to determine daylight saving transitions dates: https://stackoverflow.com/a/24378695/1159939 In addition of those dates, I need to know if the clock is going to increase or decrease and by what amount (is it always an hour?). For example, in time zone US/Pacific, when the local clock reaches 2020-03-08T02:00:00, I need to somehow get value +1h. When the clock reaches 2020-11-01T02:00:00, I need to get value -1h. In NodaTime, there is a Offset.Savings value

Serialize NodaTime JSON

☆樱花仙子☆ 提交于 2020-08-21 19:30:39
问题 I am making a prototype project of NodaTime compared to BCL's DateTime, but executing this result gives me recursionLimit exceeded error. This is the function I am using to JSONify my viewmodel. The error happens after this function returns. [HttpPost] public JsonResult GetDates(int numOfDatesToRetrieve) { List<DateTimeModel> dateTimeModelList = BuildDateTimeModelList(numOfDatesToRetrieve); JsonResult result = Json(dateTimeModelList, JsonRequestBehavior.AllowGet); return result; } My view

Get offset minutes from timezone (string) with NodaTime

半世苍凉 提交于 2020-04-10 07:41:21
问题 What's the easiest way to get the minutes if I only have a string that represents the timezone? (for example "Europe/London") So far I have: public static int ConvertFromTimeZoneToMinutesOffset(string timeZone) { DateTimeZone zone = DateTimeZoneProviders.Tzdb[timeZone]; // Need magic code to get offset as minutes } But I'm not finding an easy approach to convert it to minutes. NOTE: What I need is the offset in that specific moment in which the code is being executed. Between that timezone

Is there a concept of working-days in the Nodatime library?

风流意气都作罢 提交于 2020-03-15 07:23:05
问题 Is there a concept of working-days in the Nodatime library? What I would like to do is to somehow state that there is 5 working-days in a calender week, and then be able to ask something like: From [any given date] + 10 working-days what is the end date? or From [this calender date] to [that calender date] how many working-days are in that interval? 回答1: No, this doesn't exist as you described it. However, you can certainly use Noda Time's LocalDate object and implement your own logic. An O(n

Noda Time: Period.Between returning incorrect value

僤鯓⒐⒋嵵緔 提交于 2020-01-13 11:35:08
问题 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

How to pass a Noda Time (or any third-party type) object as a parameter in WCF?

送分小仙女□ 提交于 2020-01-03 08:56:31
问题 I have a service which uses Noda Time types ( LocalDate and ZonedDateTime ) in OperationContract parameters, but when I try sending for example LocalDate(1990,7,31) the server receives an object with the default value (1970/1/1). No error is thrown by the client or the server. Previously it worked well with the corresponding BCL types ( DateTimeOffset ). I understand Noda Time types may not be "known" by WCF, but I don't see how I am supposed to add them. I checked this page in the

How to pass a Noda Time (or any third-party type) object as a parameter in WCF?

扶醉桌前 提交于 2020-01-03 08:56:21
问题 I have a service which uses Noda Time types ( LocalDate and ZonedDateTime ) in OperationContract parameters, but when I try sending for example LocalDate(1990,7,31) the server receives an object with the default value (1970/1/1). No error is thrown by the client or the server. Previously it worked well with the corresponding BCL types ( DateTimeOffset ). I understand Noda Time types may not be "known" by WCF, but I don't see how I am supposed to add them. I checked this page in the

Convert UTC time to local time using Nodatime

非 Y 不嫁゛ 提交于 2020-01-03 07:17:30
问题 I have been provided a time in this format "ddMMyyHHmmss". I know the time is in UTC format. I would like to use the NodaTime library to convert this to my local timezone but I can't seem to figure it out. My local timezone target is to be New Zealand. Here's what I have tried: var pattern = LocalDateTimePattern.CreateWithInvariantCulture("ddMMyyHHmmss"); var parseResult = pattern.Parse(utcDateTime); if (!parseResult.Success) { throw new InvalidDataException("Invalid time specified " + date +

Converting NodaTime to Unix timestamp and the importance of LocalDateTime

≡放荡痞女 提交于 2020-01-01 17:00:06
问题 I am currently using NodaTime based on my frustrations dealing with timezones in C#'s DateTime class. So far, I'm really pleased. public static string nodaTimeTest(string input) { var defaultValue = new OffsetDateTime(new LocalDateTime(2000, 1, 1, 0, 0), Offset.Zero); var pattern = OffsetDateTimePattern.Create("yyyy-MM-dd'T'HH:mm:sso<m>", CultureInfo.InvariantCulture, defaultValue); var result = pattern.Parse(input).Value; return result.ToString(); } I have three specific questions. Above is

Converting NodaTime to Unix timestamp and the importance of LocalDateTime

梦想的初衷 提交于 2020-01-01 16:57:47
问题 I am currently using NodaTime based on my frustrations dealing with timezones in C#'s DateTime class. So far, I'm really pleased. public static string nodaTimeTest(string input) { var defaultValue = new OffsetDateTime(new LocalDateTime(2000, 1, 1, 0, 0), Offset.Zero); var pattern = OffsetDateTimePattern.Create("yyyy-MM-dd'T'HH:mm:sso<m>", CultureInfo.InvariantCulture, defaultValue); var result = pattern.Parse(input).Value; return result.ToString(); } I have three specific questions. Above is