Issue 54 in jayrock: Allow parsing date formats with the Z timezone specifier

4 views
Skip to first unread message

jay...@googlecode.com

unread,
Oct 29, 2013, 7:10:21 AM10/29/13
to jayrock...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Enhancement Priority-Medium

New issue 54 by p...@pav.gr: Allow parsing date formats with the Z timezone
specifier
http://code.google.com/p/jayrock/issues/detail?id=54

DateTimeImporter can't parse the format returned by JSON.stringify().

> JSON.stringify(new Date()) -> "2013-10-29T11:04:09.144Z"

I'm attaching a small patch that add the relevant formats to the allowed
formats.


Attachments:
DateTimeImporter.patch 1.3 KB

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

jay...@googlecode.com

unread,
Oct 29, 2013, 8:18:52 AM10/29/13
to jayrock...@googlegroups.com
Updates:
Owner: azizatif
Labels: Component-JSON

Comment #1 on issue 54 by azizatif: Allow parsing date formats with the Z
timezone specifier
http://code.google.com/p/jayrock/issues/detail?id=54

The following seems to work fine:
JsonConvert.Import<DateTime>("'2013-10-29T11:04:09.144Z'")

Are you getting an exception instead?
Do you have a unit test for the failing case?

jay...@googlecode.com

unread,
Oct 29, 2013, 11:03:26 AM10/29/13
to jayrock...@googlegroups.com

Comment #2 on issue 54 by p...@pav.gr: Allow parsing date formats with the
Strange... it fails for me.

I compile the attached file with:
> csc JRTest.cs -r:Jayrock.Json.dll

and when I run it, I get:
> JRTest.exe

Unhandled Exception: Jayrock.Json.JsonException: Error importing JSON
String as System.DateTime. ---> System.FormatException: String was not
recognized as a valid DateTime.
at System.DateTime.ParseExact(String s, String[] formats,
IFormatProvider provider, DateTimeStyles style)
at
Jayrock.Json.Conversion.Converters.DateTimeImporter.ImportFromString(ImportContext
context, JsonReader reader)
in ...\jayrock\src\Jayrock.Json\Json\Conversion\Converters\DateTimeImporter.cs:line
96
--- End of inner exception stack trace ---
at
Jayrock.Json.Conversion.Converters.DateTimeImporter.ImportFromString(ImportContext
context, JsonReader reader)
in ...\jayrock\src\Jayrock.Json\Json\Conversion\Converters\DateTimeImporter.cs:line
102
at Jayrock.Json.Conversion.Converters.ImporterBase.Import(ImportContext
context, JsonReader reader)
in ...\jayrock\src\Jayrock.Json\Json\Conversion\Converters\ImporterBase.cs:line
67
at Jayrock.Json.Conversion.ImportContext.Import(Type type, JsonReader
reader)
in ...\jayrock\src\Jayrock.Json\Json\Conversion\ImportContext.cs:line 66
at Jayrock.Json.Conversion.JsonConvert.Import[T](String text)
in ...\jayrock\src\Jayrock.Json\Json\Conversion\JsonConvert.cs:line 133
at JRTest.Program.Main(String[] args)


Attachments:
JRTest.cs 220 bytes

jay...@googlecode.com

unread,
Oct 29, 2013, 11:47:55 AM10/29/13
to jayrock...@googlegroups.com

Comment #3 on issue 54 by azizatif: Allow parsing date formats with the Z
timezone specifier
http://code.google.com/p/jayrock/issues/detail?id=54

What version are you using? I tested against version 0.9.12915 from the
following NuGet package:
http://www.nuget.org/packages/jayrock-json/0.9.12915

Just tried it against your test code:

C:\temp>nuget install jayrock-json
Installing 'jayrock-json 0.9.12915'.
Successfully installed 'jayrock-json 0.9.12915'.

C:\temp>copy jayrock-json.0.9.12915\lib\net2\Jayrock.Json.dll
1 file(s) copied.

C:\temp>csc JRTest.cs /r:Jayrock.Json.dll && JRTest
Microsoft (R) Visual C# Compiler version 4.0.30319.17929
for Microsoft (R) .NET Framework 4.5
Copyright (C) Microsoft Corporation. All rights reserved.

29/10/2013 12:04:09

C:\temp>

jay...@googlecode.com

unread,
Oct 30, 2013, 4:01:58 AM10/30/13
to jayrock...@googlegroups.com

Comment #4 on issue 54 by p...@pav.gr: Allow parsing date formats with the
I tried with the Nuget package and it works.

I built my own version from source and it's version "0.9.12915" as well,
the source code differs though!

The latest version of DateTimeImporter.cs I have is this:
https://code.google.com/p/jayrock/source/browse/src/Jayrock.Json/Json/Conversion/Converters/DateTimeImporter.cs

Looking at the decompiled code, that version of DateTimeImporter.cs uses
XmlConvert.ToDateTime, not DateTime.ParseExact.

Am I using the wrong source code?

jay...@googlecode.com

unread,
Oct 30, 2013, 6:53:38 AM10/30/13
to jayrock...@googlegroups.com

Comment #5 on issue 54 by azizatif: Allow parsing date formats with the Z
timezone specifier
http://code.google.com/p/jayrock/issues/detail?id=54

I tested both versions, the one that shipped with NuGet and one built from
the latest sources, and can't seem to reproduce this issue.

The assembly version of both is indeed 0.9.12915 because the public API
surface has remained compatible. The file versions, however, will differ.
The file version of the NuGet one is 0.9.12915.46 but the one built from
sources should have 0.9.13422.2206[1].

Are you still running into this issue with building from sources?

BTW, latest dev builds are also deployed here:
ftp://ftp.berlios.de/pub/jayrock/

[1]
https://code.google.com/p/jayrock/source/browse/src/Jayrock.Json/AssemblyInfo.cs?r=7fd760ede5f924ffcd7dfef328c9e16b27c780b5#37

jay...@googlecode.com

unread,
Oct 30, 2013, 7:33:16 AM10/30/13
to jayrock...@googlegroups.com

Comment #6 on issue 54 by p...@pav.gr: Allow parsing date formats with the
I'm now certain that I'm using an older version of the source code but I
don't see how.

$ hg clone http://jayrock.googlecode.com/hg/ jayrock
requesting all changes
adding changesets
adding manifests
adding file changes
added 64 changesets with 442 changes to 344 files
updating to branch default
cloning subrepo tools from http://tools.jayrock.googlecode.com/hg
requesting all changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 117 changes to 117 files
341 files updated, 0 files merged, 0 files removed, 0 files unresolved

$ cd jayrock
$ hg heads
changeset: 63:7fd760ede5f9
tag: tip
user: azizatif
date: Wed Oct 10 18:53:17 2012 +0200
summary: Fixes issue #49

$ hg branches
default 63:7fd760ede5f9


The file src/Jayrock.Json/Json/Conversion/Converters/DateTimeImporter.cs is
the one I'm attaching here.

At the top of the file, you can see:

public class DateTimeImporter : ImporterBase
{
private static readonly string[] _formats = new string[]
{
"yyyy-MM-dd'T'HH:mm:ss.fffffffzzz",
"yyyy-MM-dd'T'HH:mm:ss.ffffzzz",
"yyyy-MM-dd'T'HH:mm:ss.fffzzz",
"yyyy-MM-dd'T'HH:mm:ss.ffzzz",
"yyyy-MM-dd'T'HH:mm:ss.fzzz",
"yyyy-MM-dd'T'HH:mm:sszzz",
"yyyy-MM-dd'T'HH:mm:ss.fffffzzz",
"yyyy-MM-dd'T'HH:mm:ss.ffffffzzz",
"yyyy-MM-dd'T'HH:mm:ss.ffffffffzzz",
"yyyy-MM-dd'T'HH:mm:ss.fffffffffzzz",
"yyyy-MM-dd'T'HH:mm:ss.ffffffffffzzz",
"yyyy-MM-dd",
};

...
...

protected override object ImportFromString(ImportContext context,
JsonReader reader)
{
...
...
return ReadReturning(reader,
DateTime.ParseExact(reader.Text, _formats, CultureInfo.InvariantCulture,
DateTimeStyles.None));
}
catch (FormatException e)
{
throw StringError(e);
}
}

DateTime.ParseExact is being used in ImportFromString and the allowed
formats are listed in the array above.

This call to DateTime.ParseExact, with these arguments, cannot
parse "2013-10-29T11:04:09.144Z".


Can you please confirm that your version of DateTimeImporter.cs is the same
as the one attached here? Because I'm pretty sure it isn't, your version
used XmlConvert.ToDateTime while this used DateTime.ParseExact.

Thanks.


Attachments:
DateTimeImporter.cs 5.7 KB

jay...@googlecode.com

unread,
Oct 30, 2013, 1:08:58 PM10/30/13
to jayrock...@googlegroups.com
Updates:
Status: Accepted
Labels: -Type-Enhancement -Priority-Medium Type-Defect Priority-High
Milestone-Release1.0

Comment #7 on issue 54 by azizatif: Allow parsing date formats with the Z
timezone specifier
http://code.google.com/p/jayrock/issues/detail?id=54

Sorry, my bad. My test against the build from sources had your patch
already applied. :P With the patch popped, the test fails indeed.

jay...@googlecode.com

unread,
Oct 30, 2013, 1:17:11 PM10/30/13
to jayrock...@googlegroups.com
Updates:
Status: Fixed

Comment #8 on issue 54 by azizatif: Allow parsing date formats with the Z
timezone specifier
http://code.google.com/p/jayrock/issues/detail?id=54

This issue was closed by revision 533260cc34c2.

jay...@googlecode.com

unread,
Oct 30, 2013, 6:18:07 PM10/30/13
to jayrock...@googlegroups.com

Comment #9 on issue 54 by azizatif: Allow parsing date formats with the Z
timezone specifier
http://code.google.com/p/jayrock/issues/detail?id=54

FYI, this is now included in a fresh new update (0.9.16530) of the
jayrock-json NuGet package[1].
Thanks for the patch.

[1] https://www.nuget.org/packages/jayrock-json/0.9.16530
Reply all
Reply to author
Forward
0 new messages