Time / command

Is there a way to create a /command similar to the /date command? I track my blood pressure and other things and write down the time at which I take those readings so it would be handy if instead of having to look at my watch I could just type / time. Or is this something that already exists and I have just missed it?

This actually brings up another thing, I have noticed that all timestamps are GMT. How can I go about making timestamps local time?

Yes, you can create a snippet and the body of that snippet can contain any template expression including things like {{today}}

As to the time zone. It’s using UTC and this cannot currently be changed. Unless you’re willing to write some Space Script which would allow you to format dates however you like. There may be some examples of how to do this floating around in the Tricks & Techniques category.

1 Like

Thank you. I found the time template expression, and much like today, it’s {{time}}. Now my question is how can I manipulate that to adjust to the America/Chicago time zone?

Hey, can you see if this works for you? You need to paste the space-script block anywhere in your space, and run the “System: Reload” command.

```space-script
silverbullet.registerFunction({name: "texasTime"}, (dateUTC, timeUTC) => {
    const instant = Temporal.Instant.from(`${dateUTC} ${timeUTC}Z`); // we say it's UTC with the Z prefix
    const zonedDateTime = instant.toZonedDateTimeISO('UTC'); // change the object type to allow time zone operations
    const localTime = zonedDateTime.withTimeZone('America/Chicago'); // get the same moment but with specific time zone
    return localTime.toPlainTime().toString(); // format the way you like, here HH:MM:SS
});
```

I tested it like this:

```template
{{today}}
{{time}}
{{texasTime(today, time)}}
```

Which outputs for me:

2024-07-16
14:13:05
09:13:05
2 Likes

Amazing!! Thank you. Works great, but does not have a leading zero for the minute.

9:3:58

What scripting language are space-scripts written in? Javascript? Templates look very similar to the Jinja used in Home Assistant templates

It didn’t have leading zeros anywhere, should work properly now (I edited my original post for clarity).

The Space Script is indeed JavaScript, and Template Language is purpose-made for SilverBullet, but meant to be similar to what’s out there. All of that is documented on silverbullet.md, once you know the name of what you’re looking for :wink:

Thank you. I guess I need to start studying up on Javascript. I updated the script and it works perfectly!