www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - datefmt 1.0.0 released: parse datetimes and also format them

reply Neia Neutuladh <neia ikeran.org> writes:
# Sales pitch

If you've ever had to parse datetime input from multiple sources 
and everyone's standardized on ISO8601, you might have found out 
that that's not quite as standard as you'd wish. This is where 
datefmt helps you.

---
import datefmt;
auto expected = SysTime(Date(2010, 1, 1), UTC());
foreach (date; ["2010-01-01", "2010-01-01T00:00:00", "2010-01-01 
00:00:00.000Z"])
{
   SysTime parsed;
   assert(tryParse(date, ISO8601FORMAT, parsed));
   assert(expected == parsed);
}
---


# How does datefmt's parsing differ from dateparser?

dateparser is great when you have a date that's in some arbitrary 
format and you want to turn it into a sensible date. It's perfect 
for manual input.

datefmt is good when you have a restricted set of formats you 
need to accept and want to reject everything else -- generally 
when a wide range of systems using the same somewhat nebulous 
standard emit the stuff you need to parse.


# What about formatting?

datefmt can do formatting too! Most of its formatting options are 
taken from strftime, so it should be generally familiar.

And of course you can use predefined formats for RFC1123 and 
ISO8601:

auto st = SysTime(DateTime(2010, 4, 12, 15, 30, 00), UTC());
writeln(st.format(ISO8601FORMAT));
// 2010-04-12T15:30:00.000000Z
writeln(st.format(RFC1123FORMAT));
// Mon, 12 Apr 2010 15:30:00 Z


# Is anyone using it?

I've been using this in my RSS reader for the past month or two, 
during which time it's been exposed to a number of horrible 
variants of both RFC1123 and ISO8601.


# How do I get it?

Add "datefmt": "~>1.0.0" to your dub.json and Bob's your uncle!

Or download the single file from 
https://raw.githubusercontent.com/dhasenan/datefmt/master/source/datefmt.d and
put it in your project.

Licensed under MS-PL (BSD-style permissive license with patent 
grant); open an issue at 
https://github.com/dhasenan/datefmt/issues if you need a 
different license.
Dec 12 2017
next sibling parent aberba <karabutaworld gmail.com> writes:
On Tuesday, 12 December 2017 at 22:51:07 UTC, Neia Neutuladh 
wrote:
 # Sales pitch

 If you've ever had to parse datetime input from multiple 
 sources and everyone's standardized on ISO8601, you might have 
 found out that that's not quite as standard as you'd wish. This 
 is where datefmt helps you.

 [...]
Nice. These little packages are very use for someone like me doing serverside development... Dealing with dates and client data. Why not use Boost license. It makes everything easy for everyone
Dec 14 2017
prev sibling parent reply Andrea Fontana <nospam example.com> writes:
On Tuesday, 12 December 2017 at 22:51:07 UTC, Neia Neutuladh 
wrote:
 # Sales pitch

 If you've ever had to parse datetime input from multiple 
 sources and everyone's standardized on ISO8601, you might have 
 found out that that's not quite as standard as you'd wish. This 
 is where datefmt helps you.
Oh yes, thank you! +1 I think you should add some way to translate days/month in other language. Andrea
Dec 18 2017
parent Neia Neutuladh <neia ikeran.org> writes:
On Monday, 18 December 2017 at 09:03:09 UTC, Andrea Fontana wrote:
 I think you should add some way to translate days/month in 
 other language.
That would be great! Unfortunately, it requires a decent locales library.
Dec 19 2017