Files
shields/services/date/date.service.js
chris48s bd3a11b4b6 upgrade to docusaurus 3 (#9820)
* update packages

* add plugin to strip autolinks in code blocks

* fix all the documentation for MDXv3

* remove check-docusaurus-versions

in docusaurus 3 this is now a hard error, not just a warning

* port upstream change to Curl component

fixes performing the 'execute' action when pressing enter
2024-03-23 19:54:57 +00:00

40 lines
960 B
JavaScript

import { formatRelativeDate } from '../text-formatters.js'
import { BaseService, pathParams } from '../index.js'
const description = `
Supply a unix timestamp in seconds to display the relative time from/to now
`
export default class Date extends BaseService {
static category = 'other'
static route = { base: 'date', pattern: ':timestamp(-?[0-9]+)' }
static openApi = {
'/date/{timestamp}': {
get: {
summary: 'Relative date',
description,
parameters: pathParams({
name: 'timestamp',
example: '1540814400',
}),
},
},
}
static defaultBadgeData = { label: 'date' }
static render({ relativeDateString }) {
return {
message: relativeDateString,
color: relativeDateString === 'invalid date' ? 'grey' : 'blue',
}
}
async handle({ timestamp }) {
return this.constructor.render({
relativeDateString: formatRelativeDate(timestamp),
})
}
}