I struggle with custom functions for date/time I need for some more advanced date/time operations within my data… I created year.md within my /Library/Personal/ and wrote:
---
description: Get current year
tags:
- meta
---
```space-script
silverbullet.registerFunction({name: 'year'}, () => {
return Temporal.Now.plainDateISO().year;
})
```
I am not JS fun and never wrote anything in it but it looks quite sane to me. So, if I try it somewhere:
```template
{{year}}
```
I get:
Error rendering template Error: Invalid time zone specified: undefined
at data:application/javascript;base64,dmFyIHFlPU9iamVjdC5k......e09vIGFzIHBsdWd9Owo=:1:940
at data:application/javascript;base64,dmFyIHFlPU9iamVjdC5k......e09vIGFzIHBsdWd9Owo=:1:988
at innerInvokeEventListeners (ext:deno_web/02_event.js:754:7)
at invokeEventListeners (ext:deno_web/02_event.js:801:5)
at dispatch (ext:deno_web/02_event.js:658:9)
at dispatchEvent (ext:deno_web/02_event.js:1043:12)
at pollForMessages (ext:runtime_main/js/99_main.js:311:7)
at eventLoopTick (ext:core/01_core.js:175:7)
An exception was thrown as a result of invoking function renderTemplate error: Invalid time zone specified: undefined
What am I doing wrong, please? How to specify the time zone and can the time zone be set globally? I am going to write many date/time related functions and will, of course, share them. But I am stuck with this.
@bent0n If it was syntax issue I wouldn’t had asked. But this doesn’t look like syntax issue. The function does not know what time zone it should use, I guess, so I had to pass it somehow. This exact snippet was taken from this forum from here. Perhaps I’m blind but both looks the same…
@bent0n OK, will try later. But that still would not explain why the linked version works for him, meaning that something must differ somewhere. And that would be SB-specific and I doubt any LLM would find it’s path to a correct answer. How to setup timezone globally, for all functions that may request it? Is it possible?
# timedatectl
Local time: Fri 2024-10-11 16:12:20 CEST
Universal time: Fri 2024-10-11 14:12:20 UTC
RTC time: Fri 2024-10-11 14:12:20
Time zone: Europe/Prague (CEST, +0200)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
What’s unique but perfectly valid is my user’s TZ variable set to
$ echo $TZ
:/etc/localtime
I will try to set it to Europe/Prague and restart SB and we will see.
Yeah, it was the TZ variable! I set it to Europe/Prague, restarted SB and everything works now. Deno or something obviously does not use standard libraries or something. Solved. @bent0n Thanks for your effort!