I created a small Perl program to convert relative dates to absolute dates in the format that I use for my calendar. My current calendar file looks like this.
2008
08
2008-08-12
2008-08-13
09
2008-09-10
...
If I want to add a date and I don’t know the actual numbers, I can use the following program to convert the date. It will also respect the whitespace in front of the text.
#!/usr/bin/perl -w
use v5.10;
use strict;
use warnings;
use Date::Manip;
Date_Init('Language=Dutch');
my $inp = <>;
if (my ($ws, $date) = $inp =~ m/^(\s*)(.+)$/) {
say $ws . UnixDate($date, "%Y-%m-%d");
}
else {
print $inp;
}
I use Date::Manip
for parsing the date. It works with human language style
dates like thursday
. I added Date_Init
so it will parse Dutch days like
donderdag
. Also I use Perl 5.10, because I can. It has some nice features.
To use it put this script in the path. I called it refdate.pl
. To use it type
a date and type !!refdate.pl<Enter>
. In Vim this will call the program on the
current line. The date will be formatted in the YYYY-MM-DD format.