Skip to content

Be able to specify exact dates as well as relative dates #108

Open

Description

@ImperialSquid

Currently, the code in src/helpers/datetime.ts allows for setting deltas relative to some date, but that date can only be today's date ({{date}}) or two beginning of the week options({{bowm}}/{{bows}}).

It would be nice to be able to specifically set some values in the datetime, rather than have to rely on relative changes, eg if I'm making a diary for the month, with daily headers, and want to find the first day of the month, I need to use something like this:

{{datetime set_date_=date delta_days=(math (math (datetime set_date=date format="DD") "*" -1) "+" 1)}}

(Which works by extracting the day of the month, subtracting it and adding 1)

Whereas it would be nice to shortcut that with:

{{datetime set_date=date set_day=1}}

(Essentially, this is just asking for the functionality of set_date and set_time to be exposed to the user more granularly)

I think the specific order these are applied in should be:

  • Set date and time
  • Set components of date and time (day/month/hours/minutes/seconds)
  • Adjust using deltas

This would also allow for cool stuff like:

{{#repeat (datetime set_date=date set_day=1 delta_month=1 delta_day=-1 format="DD")}}

# Day {{math repeat_index "+" 1}}
Today's date: {{datetime set_date=date set_day=(math repeat_index "+" 1)}}

{{/repeat}}

To create a whole month of diary entries automatically (it finds the number of days by setting today's date, setting it to the first of the month, adding a month to get to next month, and then rolling back a day to find the last day of the current month)

Activity

  1. nishantwrp commented on Mar 21, 2025

    @nishantwrp
    Collaborator

    Hi @ImperialSquid, there is a set_date and set_time exposed already;

    const SET_DATE = "set_date";

    Did you mean something else?

  2. ImperialSquid commented on Mar 21, 2025

    @ImperialSquid
    ContributorAuthor

    I'm aware, but as far as I can tell those only work if you want to set the day, month and year all at the same time, but there's no option for setting them individually.

    Eg, if I want to set the 7th day of the current month, but leave the month and year unchanged, something like {{ datetime set_date="07/??/???? }} doesn't work.

    You have to set all of them, or none of them.

  3. ImperialSquid commented on Mar 21, 2025

    @ImperialSquid
    ContributorAuthor

    I have an idea of how to solve this btw (the issue was more just as a matter of recording the gap), I'm just very busy for the next couple of days, but when I'm free on Monday I'll try to implement it and open a PR then 👌

  4. nishantwrp commented on Mar 22, 2025

    @nishantwrp
    Collaborator

    I have an idea of how to solve this btw (the issue was more just as a matter of recording the gap), I'm just very busy for the next couple of days, but when I'm free on Monday I'll try to implement it and open a PR then 👌

    Let's brainstorm on this before you work on this. I don't think exposing set_month, etc. is needed. I can think of some better user-friendly options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions