Dart DateTime.parse() string date return by ServiceStack - servicestack

I have date string return by ServiceStack : 2013-08-25T12:06:32.8770000 but error when convert to date of Dart
DateTime.parse(mapAccount[Account.RECCREATED]);
it ok when call
DateTime.parse((mapAccount[Account.RECCREATED] as String).substring(0, 26));
Is there anyway to fix it. Thanks you.

Looks like the string don't match the internally used regular expression:
r'^([+-]?\d?\d\d\d\d)-?(\d\d)-?(\d\d)(?:[ T](\d\d)(?::?(\d\d)(?::?(\d\d)(.\d{1,6})?)?)? ?([zZ])?)?$'
But the regular expression doesn't support more that 6 digits for the milliseconds (and microseconds) part, but you supply 7 digits.
The documentation does not state which formats are supported, but gives some examples. They only state that they support a subset of ISO 8601.
Looks like your solution is the only one a the moment.
Not sure if this should be treaded as a bug, but if you think it is a bug, create a bug report here.
See the docs about DateTime.parse for more details. Looks like the problems with the parse function is already in the bug tracker.

Related

Recognition of prebuilt datetimeV2 entity in LUIS

We are using DateTimeV2 French module. The recognition is not working as expected.
We are facing trouble in the following scenario:
For query = 13/02/2018, the value recognized is 13th Feb 2018 but if the date specified in less than 12, eg, 09/02/2018, the value recognized is 2nd September 2018. There is a contradiction in these results and we are unable to process them further due to the same.
Please let me know if I am missing something out here or if there is go around for this.
You are not missing something, there is a bug in the French recognizer, we already experienced the same thing.
Origin of the problem:
In fact the problem seems to be around the order of the detection templates used by the recognizer: in French, dates are written in "day-month-year" format rather than in "month-day-year".
But if you have a look to the DateTimeDefinitions for French language here:
public static readonly string DateExtractor4 = $#"\b{MonthNumRegex}\s*[/\\\-]\s*{DayRegex}\s*[/\\\-]\s*{DateYearRegex}";
public static readonly string DateExtractor5 = $#"\b{DayRegex}\s*[/\\\-]\s*{MonthNumRegex}\s*[/\\\-]\s*{DateYearRegex}";
and the way they are used here, the problem will be that your date will fit DateExtractor4 first and the result will be used, whereas it was a value in format DateExtractor5.

Get Date/Time Pattern in ICU4J

I have a requirement where I need the pattern ICU uses to format the given date/time.
For example: If I have something like DateFormat.getDateInstance(DateFormat.SHORT, en_US).format(currentDate) gives me 5/3/2015, then I need an API which can tell me that the pattern ICU4J internally using is d/M/yyyy.
I did figure out a solution, all you need to do is convert the DateFormat into a SimpleDateFormat and call toPattern().
((SimpleDateFormat)DateFormat.getDateInstance(DateFormat.SHORT, en_US)).toPattern() returns d/M/y which is what I almost needed.

Time Data From Nest API In Correct Format?

I have noticed that the date and time fields being returned to me from the Nest API are not matching the format that the API documentation lists.
For my thermostat, I am getting the following for last_connection:
"last_connection": "2014-10-27T20:22:12.165Z"
But the API documentation lists it should be formatted as:
"last_connection": "2014-10-27T20:22:12+06:00"
Why is the Nest API returning milliseconds to me and why am I getting the character "Z" instead of the actual timezone offset that the date/time is coming from?
It looks like the example is incorrect with respect to the actual implementation. If you look at the API Reference you will see the time data is all in ISO 8601, which support both string types.
This also means you should likely use a library to support ISO 8601, rather than manually parsing the string if possible.

How to parse an ISO string value to a NodaTime Instant?

I am getting to know NodaTime and like it a lot. But I don't know it that well (yet)!
Given a value such as '2014-04-08T09:30:18Z', what are the steps required to parse such a string to a NodaTime Instant?
Thank you!
I figured this out. For others who want to do the same thing, here is what I used:
var isoString = "2014-04-08T09:30:18Z";
var result = InstantPattern.GeneralPattern.Parse(isoString).Value;
The Value property in this case returns the actual Instant object. If you omit that, the result is of type ParseResult<Instant> in this case, and has other information such as whether the parsing succeeded, etc.
http://nodatime.org/1.2.x/api/html/T_NodaTime_Text_ParseResult_1.htm
There aren't a lot of examples on Noda Time yet, but I am really liking it and turning to it more and more. Fantastic work by the team who created it. Thank you!

Input string was not in a correct format when parse in multithreading

Does Anybody can explain this:
How does it possible to throw exception when parsing "55.01"? I use multithreading.
--edit--
but... sometimes it works
This realy make me sad ;(
i use .NET 4.0 and VS2010.
--edit 2---
Ok, I made a little progress. When I do not use multithreading everything works perfect. But when I use multithreading (probably)one of a thread throw FormatException in place which is shown in the picture.
It's possible the system is set for some culture that expects a comma as the decimal point.
From http://msdn.microsoft.com/en-us/library/fd84bdyt.aspx:
The s parameter is interpreted using the formatting information in a NumberFormatInfo object that is initialized for the current thread culture. For more information, see CurrentInfo. To parse a string using the formatting information of some other culture, call the Double.Parse(String, IFormatProvider) or Double.Parse(String, NumberStyles, IFormatProvider) method.

Resources