Skip to content

Commit

Permalink
feat(tags): new template tag date.fromJournal
Browse files Browse the repository at this point in the history
  • Loading branch information
stdword committed May 20, 2024
1 parent 55792b2 commit 5d43b87
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion docs/reference__tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@ Same as [`date.today`](#date-today), but for tomorrow date.




### `.from` :id=date-from
[Day.js](https://day.js.org) object builder. See whole documentation section [here](https://day.js.org/docs/en/parse/parse) for details.

Expand All @@ -466,6 +465,18 @@ Europe/Minsk, GMT+3 \



### `.fromJournal` :id=date-from-journal
Conversion from Logseq internal date format (e.g. `20240820`) to [Day.js](https://day.js.org) object.

<!-- tabs:start -->
#### ***Template***
` ``date.fromJournal(20240820).toISOString()`` `

#### ***Rendered***
2024-08-20T21:00:00.000Z
<!-- tabs:end -->


### `.nlp` :id=date-nlp
Getting dates via natural language processing.

Expand Down
10 changes: 10 additions & 0 deletions src/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,15 @@ function date_nlp(context: ILogseqContext, query: string, now: Dayjs | string =
}
return null
}
function date_from_journal(day: number | string | Dayjs): Dayjs | null {
if (day instanceof dayjs)
return day
day = day.toString()
const obj = PageContext.parseDay(day)
if (!obj.isValid())
return null
return obj
}


/* query */
Expand Down Expand Up @@ -748,6 +757,7 @@ export function getTemplateTagsContext(context: ILogseqContext) {
}),
date: Object.assign(datesContext.date, {
nlp: bindContext(date_nlp, context),
fromJournal: date_from_journal,
}),
})
}
Expand Down

0 comments on commit 5d43b87

Please sign in to comment.