2
1
Fork 0

intro: explain using the javascript Date api over the date command

This commit is contained in:
outfoxxed 2024-04-14 04:03:15 -07:00
parent adb293de95
commit 97b2c23f9f
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
2 changed files with 30 additions and 2 deletions

View file

@ -750,7 +750,7 @@ import QtQuick
// your singletons should always have Singleton as the type
Singleton {
property string time;
property string time
Process {
id: dateProc
@ -817,3 +817,31 @@ Scope {
}
}
```
## JavaScript APIs
In addition to calling external processes, a [limited set of javascript interfaces] is available.
We can use this to improve our clock by using the [Date API] instead of calling `date`.
[limited set of javascript interfaces]: https://doc.qt.io/qt-6/qtqml-javascript-functionlist.html
[Date API]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
```qml {filename="Time.qml"}
pragma Singleton
import Quickshell
import Quickshell.Io
import QtQuick
Singleton {
property var date: new Date()
property string time: date.toLocaleString(Qt.locale())
Timer {
interval: 1000
running: true
repeat: true
onTriggered: date = new Date()
}
}
```

View file

@ -15,7 +15,7 @@ Notes:
- Semicolons are permitted basically everywhere, and recommended in
functions and expressions.
- While types can often be elided, we recommend you use them where
possible to catch proplems early instead of running into them unexpectedly layer on.
possible to catch problems early instead of running into them unexpectedly later on.
```qml
// QML Import statement