Timestamp class date/time

As discussed at:
Real World Case Study - Build (Online) Books with Markdown and the Jekyll (Static) Website Compiler - Free Ruby Reference 2.5 Book - #4 - Share - Jekyll Talk,

Ruby Date and Time classes do not support the following legal timestamp
format

  • 2010-01

    require ‘time’
    Time.strptime(“2010-01”, “%Y-%m”)
    argument out of range

    require ‘date’
    Date.strptime(“2010-01”, “%Y-%m”)
    => #<Date: 2010-01-01 ((2455198j,0s,0n),+0s,2299161j)>

I believe that the two classes date and less importantly time, can not
support a notion of a temporal instance with less absoluteness than a
day or perhaps second. For example a month in a year defaults to the
first minute of the first day of a month.

Is there another class that may be more compatible with the following
definition from Date and Time Formats ?

Different standards may need different levels of granularity in the date
and time, so this profile defines six levels. Standards that reference
this profile should specify one or more of these granularities. If a
given standard allows more than one granularity, it should specify the
meaning of the dates and times with reduced precision, for example, the
result of comparing two dates with different precisions.

The formats are as follows. Exactly the components shown here must be
present, with exactly this punctuation. Note that the “T” appears
literally in the string, to indicate the beginning of the time element,
as specified in ISO 8601.

Year:
YYYY (eg 1997)
Year and month:
YYYY-MM (eg 1997-07)
Complete date:
YYYY-MM-DD (eg 1997-07-16)
Complete date plus hours and minutes:
YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
Complete date plus hours, minutes and seconds:
YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
Complete date plus hours, minutes, seconds and a decimal fraction of
a
second
YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)

It looks like the core date class is definite moment in time with a mask
applied to it to interpret it in various different calendars.

Two code based solutions seem possible:

  • extend this class by making a range from two ‘date’
  • a new class which is calendar specific and so not dependent on
    translation from a moment.

I will search for existing compatible implementations.

Thanks Jesus.

As we have both shown the following can be interpreted without an error
call.

The other example you provided also works for me:

Time.strptime(“2010-01”, “%Y-%m”)
=> 2010-01-01 00:00:00 +0100

However 2010-01 is not equivalent to 2010-01-01 00:00:00 +0100
one is a month long period the other a second.

Some meaning is lost.