TWiki::formatTime
can generate a time that cannot be parsed by
TWiki::parseTime
.
Example:
TWiki::parseTime(TWiki::Time::formatTime(0))
This is urgent because these functions can used by plugins to populate meta-data in topics that then blows TWiki up when it is read again.
parseTime
should always be able to parse times generated by
formatTime
when it is called without a format parameter.
--
TWiki:Main/CrawfordCurrie - 30 May 2007
This I do not understand
If the formatTime does not get any format the default is
$TWiki::cfg{DefaultDateFormat} . ' - $hour:$min'
This format is always a format understood by parseTime because the $TWiki::cfg{DefaultDateFormat} only consists of a very short list of formats that parseTime should be able to decode.
When I added the new feature I also extended parseTime.
Did you test this or do you assume this fails?
I may have made a mistake in the regexes but I did add unit tests that all parse covering the new formats.
--
TWiki:Main.KennethLavrsen - 30 May 2007
I have checked more.
Your example is a bad one. When the function does not parse the time it returns 0.
But since your example tried with epoch the correct return value is 0
I tried to make a little quick plugin that just returns a value on a tag called %LAVR%
Here are some examples going further than just the default format. Using my wedding day as example (will also help me remembering it in future).
The expected result is same output as input. And additionally I am also testing the standard formats and testing all the formats that can be defined in the short list in $TWiki::cfg{DefaultDateFormat}. We agreed not to make $TWiki::cfg{DefaultDateFormat} fully flexible because this would complicate parseTime and it can never be made to understand all formats because exact same string can mean different things.
Test |
Result |
OK? |
return TWiki::Time::parseTime(TWiki::Func::formatTime(60)); |
60 |
|
return TWiki::Time::parseTime(TWiki::Func::formatTime(862617660)); |
862617660 |
|
return TWiki::Time::parseTime(TWiki::Func::formatTime(862617660, '$iso')); |
862617660 |
|
return TWiki::Time::parseTime(TWiki::Func::formatTime(862617660, '$rcs')); |
862617660 |
|
return TWiki::Time::parseTime(TWiki::Func::formatTime(862617660, '$http')); |
862617660 |
|
return TWiki::Time::parseTime(TWiki::Func::formatTime(862617660, '$year-$mo-$day - $hour:$min')); |
862617660 |
|
return TWiki::Time::parseTime(TWiki::Func::formatTime(862617660, '$year/$mo/$day - $hour:$min')); |
862617660 |
|
return TWiki::Time::parseTime(TWiki::Func::formatTime(862617660, '$year.$mo.$day - $hour:$min')); |
862617660 |
|
All the formats you can select in configure for $TWiki::cfg{DefaultDateFormat} work. The predefined named formats also works.
return TWiki::Time::parseTime(TWiki::Func::formatTime(862617660, '$day $month $year')); |
852076800 |
Becomes 01 Jan 1997 |
return TWiki::Time::parseTime(TWiki::Func::formatTime(862617660, '$year $mo $day')); |
852076800 |
Becomes 01 Jan 1997 |
So the parseTime function could probably later be extended with additional formats without time part. But that is out of scope of this bug report.
I cannot see anything wrong here. I suspect it was raised on an assumption more than actually seeing it fail.
I have spent two hours on this one now. Enough. I am setting this to No Action Required.
--
TWiki:Main.KennethLavrsen - 30 May 2007
Reopening
It bugs me that the format "30 May 2007" is not understood and parsed as "30 May 2007 00:00"
So I have a quick fix ready for that. Then at least we got a little out of all my time
--
TWiki:Main.KennethLavrsen - 30 May 2007
Committed 13993. Closing. No need to put this in release note
--
TWiki:Main.KennethLavrsen - 30 May 2007