Spaces:
Running
Running
Download HtmlDate.js from sldshr/Client-less: direct link, hf CLI and curl.
- Browser
- Download file 818 Bytes
-
https://huggingface.co/spaces/sldshr/Client-less/resolve/main/HtmlDate.js
- Command line
-
hf download hf://spaces/sldshr/Client-less/HtmlDate.js
-
curl -L -o HtmlDate.js https://huggingface.co/spaces/sldshr/Client-less/resolve/main/HtmlDate.js
818 Bytes
| import { time } from 'https://unpkg.com/ez-html-elements' | |
| /** Create a date object from a standard string representation */ | |
| export default (dateString) => { | |
| // HtmlDate PRIVATE: | |
| function dateView () { | |
| const ms = Date.now() - Date.parse(dateString) | |
| if (ms < 1500) { | |
| return `${ms} ms` | |
| } | |
| const seconds = Math.round(ms / 1000) | |
| if (seconds < 90) { | |
| return `${seconds}s` | |
| } | |
| const minutes = Math.round(seconds / 60) | |
| if (minutes < 90) { | |
| return `${minutes}min` | |
| } | |
| const hours = Math.round(minutes / 60) | |
| if (hours < 90) { | |
| return `${hours}h` | |
| } | |
| const days = Math.round(hours / 24) | |
| return `${days}d` | |
| } | |
| // HtmlDate PUBLIC: | |
| return Object.freeze({ | |
| /** Generate HTML text */ | |
| html: () => time({ datetime: dateString }, dateView()) | |
| }) | |
| } | |