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

add documentation for built in timezone config identifier #620

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/06_reference/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ pixlet render schema_hello_world.star who="Tidbyt" small=True
## Icons
Each schema field takes an `icon` value. We use the free icons from [Font Awesome](https://fontawesome.com/v6/search?s=solid%2Cbrands) at version 6.1.1 with the names camel cased. For example [users-cog](https://fontawesome.com/v6/icons/users-cog?style=solid&s=solid) should be `usersCog` in the `icon` value. When submitting to the community repo, the icon names are validated against this [icon map](https://github.com/tidbyt/pixlet/blob/main/icons/icons.go).

## Built-in Configuration
Pixlet has some built-in configuration identifiers.

### Timezone
To get the timezone of the device on which the app is installed you can use the `$tz` identifier. Typical usage would look like this:
```starlark
DEFAULT_TIMEZONE = "America/Chicago"
def main(config):
timezone = config.get("$tz", DEFAULT_TIMEZONE)

local_time = time.now().in_location(timezone)
```
When using `pixlet serve` or `pixlet render`, `config.get("$tz")` will return `None`. Use a default timezone configuration when developing as in the example.
Copy link

@dtseiler dtseiler Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can test $tz with pixlet serve by passing it in on the query string in your browser, e.g. &%24tz=Europe%2FLondon

edit: Changed my example to not use the same timezone as the default in your example. :)


## Dynamic Fields
Pixlet offers two types of fields: basic fields like `Toggle` or `Text` and dynamic fields that take a `handler` method like `LocationBased` or `Typeahead`. For dynamic fields, the `handler` will get called with user inputs. What the handler returns is specific to the field.

Expand Down
Loading