Skip to content

Commit

Permalink
add docs about date and time
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Aug 19, 2024
1 parent da3305c commit 2b9984c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/docs/lips/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,30 @@ In both platforms you can access global JavaScript objects like normal variables
;; ==> "hello, LIPS"
```

### Date and Time

Since we have full access to JavaScript, we can access the `Date` object to manipulate date and time.

```scheme
(--> (new Date "2024-01-01 12:09:2")
(getFullYear))
;; ==> 2024
```

```scheme
(define (format-part number)
(--> number (toString) (padStart 2 "0")))
(let ((date (new Date "2024-01-01 12:09:02")))
(format "~a:~a:~a"
(format-part (date.getHours))
(format-part (date.getMinutes))
(format-part (date.getSeconds))))
;; ==> "12:09:02"
```

You can also use Date time libraries like [date-fns](https://date-fns.org/).

### Interact with DOM

Here is example how to add button to the page and add onclick handler using browser DOM
Expand Down

0 comments on commit 2b9984c

Please sign in to comment.