From 2b9984c104d209ab68d846b4c6454f777edec7b2 Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Mon, 19 Aug 2024 12:15:27 +0200 Subject: [PATCH] add docs about date and time --- docs/docs/lips/intro.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/docs/lips/intro.md b/docs/docs/lips/intro.md index efd72052..e8fe2314 100644 --- a/docs/docs/lips/intro.md +++ b/docs/docs/lips/intro.md @@ -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