Tuesday, August 10, 2010

standards

There are 3 main languages in Server Automation: Java, Python and PL-SQL.

I am using this Java code
new SimpleDateFormat("dd/MM/yyyy hh:mm")
to format a Date object like this
day/month/year hour:minute

This is how I'd do it in Python:
time.strftime("%d/%m/%Y %H:%M", time.localtime())

and this is how I coded it in PLSQL a few day ago (obviously mislead by the two guys above):
TO_CHAR(_column_, 'DD/MM/YYYY HH:mm')

which resulted in me spending one hour starring at the same output '09:08'. For one hour I was tricked into thinking the business logic that updated the column was wrong. But the hour passed by and Oracle said to me: now it's '10:08', which lead me to think we were not speaking the same language ... definitely I was not mastering Oraclian (=PLSQL) properly: it turned out that if I wanted minutes, it should be MI and not mm.

For that hour ... someone should take the blame, what about the creators of one of these languages for not following the conventions set out by the others. It should be the ones that arrived afterwards, right? Or probably it should be the standard bodies for not getting into date formatting.

Or should I think that French sounds sexier than English, learn both and embrace the diversity? But I have not been acquainted to many sexy engineers over time ... so can we all agree from this point on that when I want the time printed ... it should be HH:minutes? I'm hearing they spell it the same in France ...

1 comment:

Lucian Revnic said...

Here are two examples from Perl (not the best ones but popular):

Version 1.
my ($sec, $min, $hour, $day, $month, $year, $wday, $yday, $dst) = localtime();
#1900 is considered year 0
$year += 1900;
#month range is 0..11
$month += 1;
$timeStr = "$year/$month/$day $hour:$min:$sec";

Version 2.
$timeStr = strftime("%Y/%m/%d %H:%M:%S", localtime());