`:date` inflation returning a timestamp instead of a date
When a :date col-type is inflated, a local-time timestamp is returned instead of either just the string value of the date or an object representing a date. See here: https://github.com/fukamachi/mito/blob/c337a17bc9ff6dc0ea9017601d829aab99ec5e2e/src/core/dao/column.lisp#L79
https://github.com/fukamachi/mito/blob/c337a17bc9ff6dc0ea9017601d829aab99ec5e2e/src/core/dao/column.lisp#L86
Note that deflation is fine because it allows for the string value: https://github.com/fukamachi/mito/blob/c337a17bc9ff6dc0ea9017601d829aab99ec5e2e/src/core/dao/column.lisp#L134
I would hope standard behavior for :date returns a date, whether as a string or an object, not a different data type.
Can we either return a string or at least use a date typed object?
There are a few libraries to deal with dates specifically, since local-time only deals with timestamps. See here: https://github.com/CodyReichert/awesome-cl?tab=readme-ov-file#date-and-time
Two in particular jumped to mind, both built on top of local-time:
- https://github.com/copyleft/calendar-times
- https://github.com/jwiegley/periods
It seems only periods is available in quicklisp: https://www.quicklisp.org/beta/releases.html
I would be happy to make a PR to fix this. I have no horse in choosing whichever library, I would just like for the dates to return a correct data type.
What do you think?
Originally posted by @daninus14 in https://github.com/fukamachi/mito/discussions/184
Actually take it back, it looks like periods doesn't actually deal with dates. Just found the docs: https://lisp-maintainers.github.io/periods/#Fixed-time
The most basic element of time used by the PERIODS library is the fixed-time structure. At present, this is just a type alias for local-time structures2, so all of the operations possible on a local-time are applicable to a fixed-time.
So calendar-times seems like the only one who has date data types.
> (caltimes:parse-timestring "2025-11-24" 'caltimes:date)
#<CALENDAR-TIMES:DATE 2025-11-24>
> (caltimes:format-caltime nil (caltimes:parse-timestring "2025-11-24" 'caltimes:date))
"2025-11-24"
I just added an issue for it to be added to quicklisp: https://github.com/quicklisp/quicklisp-projects/issues/2507
Well, since calendar-times is not yet in quicklisp, not sure if this will get added until quicklisp updates.
I am sharing here my implementation for when it's needed so that we can make a PR
(defmethod mito.dao.column:inflate-for-col-type ((col-type (eql :date)) value)
(etypecase value
(integer
(calendar-times:universal->date value))
(string
(calendar-times:parse-timestring value 'caltimes:date))
(null nil)))
Note that I had to make some additions to calendar-times itself for the conversions. See here: https://github.com/copyleft/calendar-times/pull/4
Hopefully that PR will have been merged by the time quicklisp adds the library.
Update: The PR for calendar-times was accepted.