Here's a good start using static words that do not require you to treat them as a DSL (domain specific language).
# 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}; }
Example,
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, 2022    
The challenge is defining and implementing DSL, then translating that to the "date math" that will need.
For example, SQL uses something very primative and structured when what you want is not NOW(), e.g.,
SELECT DATE_ADD('2008-01-02', INTERVAL 31 DAY)
So my suggestion is to start with static word or phrases, then focus specifically on the challenge to develop a
DSL (or implement a well established one) that can then be parsed and then used to get the numbers you need to
perform the date math. Hope that helps.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.