I have a small CGI script that accepts dates from users and lets them do a database lookup. This script has been working for years with minor changes. The last time I changed the script was to upgrade the server to Debian Squeeze, where there were some minor syntax changes.
However in the last month or so, the date search function stopped working. Many people had the dates default to the current day, regardless of what they entered into the CGI. Testing revealed that the date function worked fine, as long as proper syntax was used. But I use date::manip to make it as user friendly as possible!
I've cut the troublesome part of the script out, and it is included below together with sample output.
#!/usr/bin/perl -T
use strict;
use Date::Manip;
my $raw_date1 == $ARGV[0];
+
# Default to today if date is blank:
+
if ( $raw_date1 == "" ) {
+
print "In blank date check. But is the date truly blank? It
+is in fact \"$raw_date1\"\n";
+
$raw_date1 = UnixDate("today","%Y-%m-%d");
};
$raw_date1 = ParseDate($raw_date1);
+
# fix the dates to MySQL format:
+
my $date1 = UnixDate($raw_date1,"%Y-%m-%d");
+
print "$raw_date1 was changed to $date1\n";
sorry for the cut & paste munging.
And here is the output:
I expect this:
jfzuelow@city-liza-lnx:~$ ./odd-date.pl
+
In blank date check. But is the date truly blank? It is in fact ""
+
2013020200:00:00 was changed to 2013-02-02
And I expect this:
jfzuelow@city-liza-lnx:~$ ./odd-date.pl "15 jan"
2013011500:00:00 was changed to 2013-01-15
However this is very confusing to me, and my users:
jfzuelow@city-liza-lnx:~$ ./odd-date.pl "jan 15"
In blank date check. But is the date truly blank? It is in fact "jan
+ 15"
2013020200:00:00 was changed to 2013-02-02
Ideas?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.