silverbulletmd / silverbullet

The knowledge hacker's notebook
https://silverbullet.md
MIT License
2.32k stars 168 forks source link

Timezone ignored on Docker container #680

Closed rc2dev closed 1 month ago

rc2dev commented 7 months ago

First of all, thanks for Silverbullet!

I have a command to create a note with name "{{ today }} {{ time }}". However, time is UTC instead of local.

My compose.yaml:

services:
  silverbullet:
    image: zefhemel/silverbullet
    container_name: silverbullet
    restart: unless-stopped
    environment:
      - SB_USER=${USERNAME}:${PASSWORD}
      - PGID=1000
      - PUID=1000
      - TZ=America/Sao_Paulo
    volumes:
      - /mnt/dietpi_userdata/silverbullet:/space
    networks:
      - proxy-net

networks:
  proxy-net:
    external: true

Running date inside the container returns UTC time.

I've also tried, with no luck:

   volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/etc/timezone:/etc/timezone:ro"
rc2dev commented 7 months ago

More info: {{ today }} seems to respect timezone fine, while {{ time }} doesn't.

daydaya commented 6 months ago

I encountered the same problem

zefhemel commented 6 months ago

I don't think this is a docker issue, it's indeed a UTC issue. The current time function gives you UTC time, you can define a space function that gives you the local time. Try this:

Somewhere in your space:

```space-script
silverbullet.registerFunction({name: "localTime"}, () => Temporal.Now.plainTimeISO().toString().split('.')[0])
```
Then call it somewhere:
```template
{{localTime}}
```
daydaya commented 6 months ago

I don't think this is a docker issue, it's indeed a UTC issue. The current time function gives you UTC time, you can define a space function that gives you the local time. Try this:

Somewhere in your space:

```space-script
silverbullet.registerFunction({name: "localTime"}, () => Temporal.Now.plainTimeISO().toString().split('.')[0])

Then call it somewhere:

{{localTime}}

This is useful for me, thank you very much

bjeanes commented 1 month ago

I opened #981 but was redirected to this original issue, which is related. I have closed the original as it is a duplicate.

While creating a space script function is an acceptable workaround in some cases, where it falls short is that the out-of-the-box Journal features in Library/Core/Journal use both {{today}} and {{time}} in its filename generation, which creates misleading and potentially confusing names.

This is demonstrated here, where the files were created in the order specified in the annotation:

image

A note created at 9:57 AM AEST (23:57 UTC) and another created at 10:05 AM AEST (00:05 UTC) are created out of order.

So, the issue in my mind isn't that {{time}} doesn't respect timezones, but that it is used in concert with {{today}} which does appear to. The dates in the journal should be strictly UTC or strictly local by default.

zefhemel commented 1 month ago

Ok, I'm now formatting all dates and times to whatever the local setting is. Let's hope this works well. A space reindex may be required for this to take effect.