Example,# referred to as 'words2date.pl' below use strict; use warnings; use POSIX qw/strftime/; my $datewords = join q{ }, @ARGV; # Take "vague" words and convert them into a # date/time stamp, e.g.,: "now", "today", "5pm Friday" sub format_epoch { my $epoch = shift; # example, Tuesday, December 12, 1995 return strftime(qq{%A, %B %d, %Y},localtime($epoch)); } my $static_phrases = { now => sub { print format_epoch(time) }, today => sub { print format_epoch(time) }, tomorrow => sub { print format_epoch(time + 86400) }, yesterday => sub { print format_epoch(time - 86400) }, }; if ( defined $static_phrases->{$datewords} ) { $static_phrases->{$datewords}->(); } else { warn qq{[WARNING] I do not understand what you mean by, "$datewords" +\n}; }
shell> perl words2date.pl now Tuesday, September 20, 2022 shell> perl words2date.pl today Tuesday, September 20, 2022 shell> perl words2date.pl tomorrow Wednesday, September 21, 2022 shell> perl words2date.pl yesterday Monday, September 19, 2022The challenge is defining and implementing DSL, then translating that to the "date math" that will need.
So my suggestion is to start with static word or phrases, then focus specifically on the challenge to develop aSELECT DATE_ADD('2008-01-02', INTERVAL 31 DAY)
In reply to Re: How to convert a vague time specfier into a concrete timestamp
by perlsherpa
in thread How to convert a vague time specfier into a concrete timestamp
by chrestomanci
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |