New Tiddler with due-date Set for Next Week

I want to use a button to create a new tiddler today and set the due date field for next week

<$button> Create Task
<$action-sendmessage $message="tm-new-tiddler"  
$param="TemplateTiddler" 
title="DestinationTiddler"
due-date=????
/>
Clone Tiddler
</$button>

What should I use instead of ??? above to set a due date for next week (7 days later).
The format of date can be 20211122 or 2021.11.22? Is there any core function for this?

To my knowledge there isn’t something in the core for this unfortunately, though in a recent exchange on a post of mine, @jeremyruston suggested extending the add filter operator made sense.

I’m NOT a javascript expert by any means, basic tinkerer, but I do use date math regularly in my own wikis, so you’re welcome to try my extensions here but BACK UP FIRST. Note that these both all expect 8 digit dates like 20211122 for today, so be aware of that.

dateadd (Macro)
dateadd.json (1.6 KB)
This is a javascript macro which means after importing you need to save/refresh for it to be available. Syntax is like <<dateadd days:"7">> and is based off of @inmysocks 's add-time macros (Jed’s site). My addition is that you can give it a basedate so it’s not locked into today like <<dateadd basedate:20211122 days:7>> for instance. If you leave basedate out it will use today.

adddays (Filter operator)
adddays.json (1.2 KB)
I just finished this today, so far less testing done, but seems to work okay. This is useful if you have an imcoming date in the filter, and then want to add days. I’ll eventually build weeks, months, years on top of it. So something like {{{ [[20211122]adddays[1]] }}} will be 20211123 (tomorrow).

Then you can combine both to get {{{ [<dateadd>adddays[7]] }}} for a date 7 days from today. Or you could use just dateadd and store it in a variable using <$wikify>, your preference.

3 Likes

A work around I have suggested on many occasions is to set a next-week field with todays date, and the list that lists items next week deals with listing items with a next-week value from the last 7 days using the days operator.

This approach has many other advantages because if you don’t do it next week, it can appear the week after etc… , you could even just have a single date and test if for being 1 week, 1 fortnight, one month, quarter or year. This thing is you can also see when you set it, without ever touching the tiddler again. If you have a separate done-date when you do finish it you can actually compare the done with the intended date.

Also alone or combined with the above method, let people pick a date from a calendar, its is easy to see when next week is, but they could also set a date to do it in three weeks with the same mechaisium. eg do-week-from-date, or simple maths can be used to set an item due on a week number, and week number only need simple maths and to jump years after 52.

1 Like

@TW_Tones this is very clever solution! It does not actually show a date, but items with due date from now in 7 days!

It worth to be documented with some examples! Very powerful!

@stobot I like your solution and maths you added for dates! Tiddlywiki needs to be improved in this area! I also appreciate the great work by Eric Shulman on this field.

2 Likes

Nice work @stobot, good to see that you found your way around writing a filter operator.

If you prefer add-day as opposed to addday for readability, that is possible.
You just have to use exports["add-day"] in your code as opposed to exports.add-day.

Posting back a quick update/replacement on adddays - adding addweeks, addmonths, addyears

datemath.json (3.7 KB)

I say replacement because I changed the name (so if you installed the old one I posted above, delete it first)

@saqimtiaz - I avoided the dash as the convention seemed mostly to dash-less in the filter operator list. Of all of them listed, only… 3? seem to have dashes (search-replace… but not addsuffix for instance).

@TW_Tones - I’m having a hard time understanding your suggestion, though it does ring a bell as something you’ve mentioned before. I think I get that you’re kind of reversing how days[] works, but am interested in your “other advantage” example.

We don’t really have a set convention for filter operator names in this regard at the moment. The main reason I suggested using a dash is that addday with the three consecutive d characters is not that easy to read. Otherwise it is totally fine. :smiley:

I have recently started prefixing my operator names to avoid future clashes with the core. For example: notation:search[] for a filter that is part of the Notation plugin and _match for a filter that is not meant to be used by end users. I’m at 25+ plugins and keeping things consistent and managing dependencies is getting to be a real challenge.

1 Like

@stobot
Is it possible to add filter operator with suffix like

add:day[1]  
add:week[1]  

etc.

The issue will be this overwrite the current add operator!!

1 Like

I would assume it’s possible @Mohammad. Unfortunately I spent hours trying to figure out how and couldn’t do it. As I mentioned I don’t know Javascript at all, I just faked it long enough to get lucky here. The addsuffix.js is a relatively simple starting point that I could take Jed’s macros and addsuffix.jsand “Frankenstein” them together. The math.js module has a bunch of extra stuff I don’t understand (all the makeNumericBinaryOperator type stuff) and I kept getting type errors I couldn’t figure out.

My assumption is that if this effort was picked up by a real developer they would implement it using the syntax you describe. Unfortunately that’s just a little out of my league at the moment.

1 Like

I cannot recall if a GitHub issue was created for extending the add operator. If not, I recommend creating one.

Ok, think I did it right - issue #6267 and pointed back here.

2 Likes

The GH link is: [IDEA] Extend add filter operator for date math · Issue #6267 · Jermolene/TiddlyWiki5 · GitHub

1 Like

add:month
add:quarter
add:halfyear
add:seconds
add:hour
add:day

and presumably matching subtract(s)

Meaning if the parameter is date related it treats the input as a date. Presumably it uses the “prefix” so it is valid for both YYYY0MM0DD and the full Tiddlydate YYYY0MM0DD0hh0mm0ss0XXX or parts there of.

Stobot,

The trick is you use date time stamps, using now, or a date picker.

For example;
If I place a date/time stamp in a field called fortnight, you could say the field contains a “fortnight from now”.
When listing tasks the list widget which can list "tasks with a fortnight from now more than 14 days ago using days[-14]
The advantages of this is

  • its easy to see older items
  • Add a tag reoccurring, and when you do the fortnightly task, you just stamp it again with now. And it will reappear next fortnight. With no reoccurring consider then done date as completed.
  • If you forward date it you can use the fortnight field (or any other) to schedule a fortnight from date eg do a fortnight from 1st January
  • Since the date stamp is in the fieldname its simple to have multiple such fields like weekly, monthly, quarterly and yearly (Birthdays and anniversaries with slight variation)
  • using a date field with a value as not only the scheduled but as a flag for a status eg:
    A tasks is done if it has a done date.
    The dates can be compared with done, created, modified or touched date time stamps to establish all kinds of information about your task management such as how long from start to done. When it was done, when it was last edited (modified).
1 Like

Post script. It is also nice to have sunset or expiry dates eg

  • If you don’t do it by sunset date you failed
  • do this by this expiry date otherwise forget it.
1 Like

Hi everyone,
this is indeed a very useful macro and as @Mohammad mentioned earlier needs some documentation and examples to explain it for the newer users of TiddlyWiki, myself included.

@TW_Tones pointed out that I could consider using this in the post on
PHR (Personal Health Record).

As you are an avid user of tasks and journals that widely use dates, could you please provide some basic examples of usage of the macro and also your work around that we could use and adapt where necessary.

1 Like

Hello @Scot - I can’t tell who this question is directed to. My name isn’t listed, though I was the one that posted the filter operator code - so maybe it’s me?

In addition to the example usage I showed above, here’s a few more examples to show it’s most basic usage:

Notes:

  • It can be used within the filter against a real date like modified OR a stored custom date (how I use it) like duedate, or a hard-coded date value in at least YYYYMMDD format like shown for today’s date.
  • You can chain them as much as you want (days, weeks, months, years etc.)
  • I didn’t show it, but you can use negative values to do “subtract”

In terms of use, most times it’d be used like this:

<$button>Add Week
<$action-setfield $tiddler="mytasktiddler" $field="duedate" $value={{{ [{!!duedate}addweeks[1]] }}} />
</$button>
2 Likes

Hi @stobot
Please accept my apology as I should have included you in my post as it was your filter operator code that initiated the post. I was however directing my question to @TW_Tones initially and secondly to @Mohammad for his requests.

Thank you for replying so quickly. Your reply was exactly what was required and explains what tiddlers are needed to make a working example.