kastnermario / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

Implement support for timestamps #284

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

I'm currently trying to incorporate the yaml-cpp in a Qt-based project.  One 
thing I need to serialise and deserialise is timestamps.  I haven't yet 
stumbled on a way to do this.  Specifically, I'm after a QDateTime, but I can 
tolerate a time_t or some generic date/time class.

The YAML way of giving these seems to be ISO8601 format, see example 2.2 here:
http://www.yaml.org/spec/1.2/spec.html#id2761292

I'm guessing the way forward is to implement custom serialisation methods.  If 
I come up with something I'll post back here.

Original issue reported on code.google.com by stua...@longlandclan.id.au on 10 Mar 2015 at 2:40

GoogleCodeExporter commented 8 years ago
Okay, just figured out an example using the QDateTime type in Qt.  For a more 
generic version, you'd need to parse out the ISO8601 date yourself and come up 
with a C++ class to represent it or use time_t; QDateTime already has the logic 
for parsing ISO8601.

I think this is probably the only native YAML type that is missing in yaml-cpp, 
so if we could get some standard representation going, that'd make others' 
integration efforts a lot easier.

Original comment by stua...@longlandclan.id.au on 10 Mar 2015 at 8:58

Attachments:

GoogleCodeExporter commented 8 years ago
I'm not convinced this is something that should go in the library proper, since 
it's not a native C++ data type. Maybe once I switch to C++11 this could be 
used with the new date types.

Original comment by jbe...@gmail.com on 10 Mar 2015 at 9:41

GoogleCodeExporter commented 8 years ago

Original comment by jbe...@gmail.com on 10 Mar 2015 at 9:41

GoogleCodeExporter commented 8 years ago
This is true, C++ doesn't have a native data type, but it doesn't have a Binary 
type, yet there is YAML::Binary.

I've since found the parsing of timestamps in Qt is a little deficient (it 
drops the fractional-seconds part it seems and has problems with timezones) so 
I've built a Timestamp class that can be used as an initial stepping stone for 
implementing conversion to other date/time types.  Attached is a more complete 
implementation that does string parsing and generation.

C++11 support would be nice, but not everyone is using it just now (GCC has it 
marked as "experimental", so I'm staying with the earlier standard).  The 
attached class at least implements the parsing bit, so you could then extend it 
to support the C++11 types.

Original comment by stua...@longlandclan.id.au on 29 Mar 2015 at 11:53

Attachments:

GoogleCodeExporter commented 8 years ago
Binary data is just a sequence of bytes - I needed to wrap it in a type to be 
able to use it easily.

Timestamps have much more structured data, so I'm less inclined to roll our 
own. I'll keep this in mind, though.

Original comment by jbe...@gmail.com on 30 Mar 2015 at 12:05

GoogleCodeExporter commented 8 years ago
This issue has moved to github: https://github.com/jbeder/yaml-cpp/issues/284

Original comment by jbe...@gmail.com on 1 Apr 2015 at 3:32