Created
July 21, 2022 00:02
-
-
Save jkmartindale/9478cc507dd1190afd481384d8fd4a6a to your computer and use it in GitHub Desktop.
"Show" formula for a Notion-backed recurring task system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(or(prop("Pinned"), largerEq(floor((timestamp(now()) + toNumber(slice(formatDate(now(), "ZZ"), 0, 3)) * 3.6e+6 + toNumber(replace(formatDate(now(), "Z"), "\\d{2}:", "")) * 60000) / 8.64e+7) - floor((timestamp(prop("Edited")) + toNumber(slice(formatDate(now(), "ZZ"), 0, 3)) * 3.6e+6 + toNumber(replace(formatDate(now(), "Z"), "\\d{2}:", "")) * 60000) / 8.64e+7), if(empty(prop("n Days")), 1, prop("n Days"))) and or(empty(prop("Days of Week")), contains(prop("Days of Week"), formatDate(now(), "ddd"))) and or(empty(prop("Day of Month")), date(now()) == prop("Day of Month"))) or prop("Edited") < prop("Start Date")) and (now() > prop("Start Date") or empty(prop("Start Date"))) | |
// The above but slightly more readable | |
( | |
or( | |
prop("Pinned"), // Force display if pinned | |
largerEq( // Show task if it has been more than n days since edit time | |
// but we round down to midnight and adjust for time zone | |
floor((timestamp(now()) + toNumber(slice(formatDate(now(), "ZZ"), 0, 3)) * 3.6e+6 + toNumber(replace(formatDate(now(), "Z"), "\\d{2}:", "")) * 60000) / 8.64e+7) | |
// ^ adjust for timezone hours offset | |
// v adjust for timezone minutes offset (I got bored) | |
- floor((timestamp(prop("Edited")) + toNumber(slice(formatDate(now(), "ZZ"), 0, 3)) * 3.6e+6 + toNumber(replace(formatDate(now(), "Z"), "\\d{2}:", "")) * 60000) / 8.64e+7) | |
, | |
// Default to daily if repeat every n days unspecified, helps with weekly/monthly | |
if(empty(prop("n Days")), 1, prop("n Days")) | |
) and or( // Weekly occurrences, additive constraint | |
empty(prop("Days of Week")), contains(prop("Days of Week"), formatDate(now(), "ddd")) | |
) and or( // Monthly occurrences, additive constraint | |
empty(prop("Day of Month")), date(now()) == prop("Day of Month") | |
) | |
) | |
// Can't remember why this is here but I think I remember it being important | |
or prop("Edited") < prop("Start Date") | |
) | |
// Start date takes precedence over everything else | |
and( | |
now() > prop("Start Date") | |
or empty(prop("Start Date")) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment