Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More date utilities in handlebar template and config file #152

Closed
rayandrew opened this issue Jan 11, 2022 · 9 comments · Fixed by #156
Closed

More date utilities in handlebar template and config file #152

rayandrew opened this issue Jan 11, 2022 · 9 comments · Fixed by #156

Comments

@rayandrew
Copy link

Hi!
Thank you for this application! It really helps me maintain my second brain.

However, I have specific use cases such as daily planning.
I usually create a plan for tomorrow in the night.
I think it would be good if this application has {{ date tomorrow (format) }} .

Or is there any other way to get the tomorrow date?

Thank you again!

@rayandrew
Copy link
Author

For now I use this hack to make it works.

#!/usr/bin/env bash

tomorrow=$(date -v+1d +%A-%B-%Y-%m-%d)

arr=(${tomorrow//-/ })

dayname=${arr[0]}
monthname=${arr[1]}
year=${arr[2]}
month=${arr[3]}
day=${arr[4]}
when="$year-$month-$day"

mkdir -p $BRAIN_DIR/plans/$year/$month
cd $BRAIN_DIR
zk new --no-input "plans" \
  --extra dayname="$dayname",monthname="$monthname",when="$when",year="$year",month="$month",day="$day"
[group.plans]
paths = [
    "plans",
]

[group.plans.note]
# uncomment if zk supports {{date tomorrow}}
# filename = "{{date now '%Y'}}/{{date now '%m'}}/{{date now '%Y-%m-%d'}}"
filename = "{{extra.year}}/{{extra.month}}/{{extra.when}}"
extension = "md"
# template = "plan/default.md"
template = "plan/hacky.md"
---
title: Plan of {{ extra.dayname }}, {{ extra.monthname }} {{ extra.day }}, {{ extra.year }}
description: Plan of {{ extra.dayname }}, {{ extra.monthname }} {{ extra.day }}, {{ extra.year }}
slug: {{ extra.year }}/{{ extra.month }}/{{ extra.day }}
date: {{ extra.when }}
type: plan
keywords:
  - plan
  - plans
roles:
  - super-admin
  - admin
---

What will I do at {{ extra.dayname }}, {{ extra.monthname }} {{ extra.day }}, {{ extra.year }}?

Results:

---
title: Plan of Tuesday, January 11, 2022
description: Plan of Tuesday, January 11, 2022
slug: 2022/01/11
date: 2022-01-11
type: plan
keywords:
  - plan
  - plans
roles:
  - super-admin
  - admin
---

What will I do at Tuesday, January 11, 2022?

Feel free to close this!
If you have any better suggestions, feel free to reply.
This proves that the program is future-proof indeed!

Thanks!

@mickael-menu
Copy link
Member

I recently merged in main a new --date flag for zk new, which should address this issue.

It will replace the default value of now in the template and can be used like this:

$ zk new --date tomorrow

Let me know if that solves your problem.

@rayandrew
Copy link
Author

Thank you that fixes the problem!

However, I find 1 issue, so far. Let me know if I am wrong.

➜ brain plan --date tomorrow --dry-run
/Users/rayandrew/brain/plans/2022/01/2022-01-14.md
---
title: Plan of ,  ,
description: Plan of ,  ,
slug: //
date:
type: plan
keywords:
  - plan
  - plans
roles:
  - super-admin
  - admin
---

What will I do at ,  , ?

It shows that I create 2022-01-14.md
However, it will be 2022-01-13 tomorrow (in my timezone)

Is the date utilities in zk not respecting the timezone?

Thanks!

@mickael-menu
Copy link
Member

Ha I'll take a look, which timezone are you in?

In the meantime, you should be able to pass a RFC 3339 date as:

$ zk new --date `date -v+1d +...`

@rayandrew
Copy link
Author

Hi, I am in Central Standard Time.

$ zk new --date `date -v+1d +T`

Yes this code works flawlessly!

@mickael-menu
Copy link
Member

@RayAndrews Would you mind testing zk new --date tomorrow from the fix/issue-152 branch again? This should fix the timezone issue.

@rayandrew
Copy link
Author

Yes!

This is the result:

  • Tomorrow date (you can see my tmux statusline)

image

  • Yesterday date

image

it worked flawlessly!


However there is one bug:

It seems passing full RFC 3339 date will throw error.
CMIIW, I assume 2022-01-17T17:53:12 is a valid RFC 3339.

date -v+1d +%Y-%m-%dT%T will become 2022-01-17T17:53:12

image

@mickael-menu
Copy link
Member

Right, Go supports by default only the full RFC 3339 template including the timezone.

I added a few more formats:

https://github.com/mickael-menu/zk/blob/c429517c6bdb25c19e040a43238b3904847efcb2/tests/cmd-new.tesh#L69-L81

It's merged in main now 👍

@rayandrew
Copy link
Author

I have tested and it works well for RFC3339 full timestamp now!

Thank you @mickael-menu!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants