jadenthem / google-refine

Automatically exported from code.google.com/p/google-refine
0 stars 0 forks source link

Support formatting dates into strings #184

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Calling toString() on a date returns null right now. It'd be good to be able to 
use either toString() or another function, say, format() to format dates into 
strings.

Original issue reported on code.google.com by dfhu...@google.com on 9 Nov 2010 at 6:21

GoogleCodeExporter commented 8 years ago
For me, it returns some strangely formatted date string.

row value           value.toString()
4.  2008-08-07T00:00:00Z    Thu Aug 07 00:00:00 MSD 2008
5.  2009-12-22T00:00:00Z    Tue Dec 22 00:00:00 MSK 2009
7.  2007-11-06T00:00:00Z    Tue Nov 06 00:00:00 MSK 2007
24. 2010-10-01T00:00:00Z    Fri Oct 01 00:00:00 MSD 2010
27. 2010-05-13T00:00:00Z    Thu May 13 00:00:00 MSD 2010
30. 2010-07-06T00:00:00Z    Tue Jul 06 00:00:00 MSD 2010

It uses this format regardless of first argument that should be format string:

row value           value.toString('yyyy-MM')
4.  2008-08-07T00:00:00Z    Thu Aug 07 00:00:00 MSD 2008
5.  2009-12-22T00:00:00Z    Tue Dec 22 00:00:00 MSK 2009

Also, freebase does not accept 'date' objects stored in refine table, as they 
are converted to string using the same format:

    Action  Message Details fb_id
1.  LOAD_TRIPLE triple is not valid to be loaded    (ERROR): Invalid literal Wed 
Jan 21 00:00:00 MSK 2009 of type /type/datetime: Literal value (Wed Jan 21 
00:00:00 MSK 2009) must be valid mql datetime   
    "$Name_en_0" --(/internet/website/launched)--> "Wed Jan 21 00:00:00 MSK 2009" [{"recon":{"s":"rec1289912419390812104"}}]

Original comment by incredible.angst on 16 Nov 2010 at 10:34

GoogleCodeExporter commented 8 years ago
I'll take a look at this.  David's case is simple.  The code currently doesn't 
use a default format if none is provided.  It does work if you give it an 
explicit format string.

I'm unsure if the behavior reported in comment #1 is related.  How are you 
invoking toString() (ie in what context)?  When I try it, I get the behavior 
that David reported.  Can you also provide more information on your operating 
system, locale, and Java version? 

Original comment by tfmorris on 26 Nov 2010 at 11:39

GoogleCodeExporter commented 8 years ago
value.toString() on a date will now format the date using the default locale 
formatting.  value.toString('<format string>') will format the date according 
to the given format string (that part was already implemented).

I'm of two minds as to whether this is the best solution or if we should make 
the default be ISO 8601 (and MQL) compatible.  If anyone has strong opinions, 
please speak up.

incredible.angst - please open a separate bug report for your problem.  I can't 
see how it could be related.

Original comment by tfmorris on 26 Nov 2010 at 11:50

GoogleCodeExporter commented 8 years ago

Original comment by tfmorris on 9 Jun 2011 at 7:58