Menu

DateFormatsSupportedInCommandLine

TheLiv

What Date/Time Formats Should We Support for Date/Time Parameters?

As per [#8] we do have some issues when dealing with date/times passed in. However, assuming those will get fixed (soon!), here are the parameters expected to be followed by a date/time in the command line:

  • -bd or --before-date = specifies a date/time to filter versions older than the specified date

Formats Supported

This is based on the envisaged common usage scenarios of the tool, which as far as I can tell (based on my own experience) comprise of:

  1. specify a full year/month/day/hour/minute/second -- this is rather rare, but can be encountered for systems where in a second there are occasionally a lot of writes to S3 and we want to narrow it down to that level
  2. specify just year/month/day/hour/minute -- I would argue this is more common when dealing with S3, since it is a slow storage system and as such second might not be relevant
  3. (probably the most common one when cleaning up/purging) specify just year/month/day -- and assume 00:00:00 for time

Based on the above, we will be supporting the following 3 formats see SimpleDateFormat:

  1. yyyy-MM-dd HH:mm:ss
  2. yyyy-MM-dd HH:mm
  3. yyyy-MM-dd

If any other date/time format is specified in the command line the program will bail out with an error message indicating wrong date format.

How Does The Code Decide Which Format Has Been Specified?

The code simply tries each format one by one, in the order specified above (starting with 1, then 2, etc.). If at any point it manages to parse successfully the date/time string using one of the formats above into a valid date it assumes that the date/time has been specified in the current format and stops returning the parse date.

In other words, it tries to parse first the string using the full date + time format specified at 1. If this returns a valid date and doesn't raise an error, it returns that and doesn't try any of the other formats. If however, this fails, it proceeds to trying format number 2. Again, if this renders a valid date and no errors it simply returns the parsed date and doesn't continue with 3; if however this fails, it then tries to use 3rd format, and so on.


Related

Tickets: #8
Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.