Files
shields/services/date/date.service.js
Caleb Cartwright 0b31461af6 convert some service classes to static props, run [date david debian debug dependabot] (#5539)
* refactor(date): convert to static props

* refactor(david): convert to static props

* refactor(debian): convert to static props

* refactor(debug): convert to static props

* refactor(dependabot): convert to static props

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
2020-09-14 21:54:22 +00:00

42 lines
1.0 KiB
JavaScript

'use strict'
const { formatRelativeDate } = require('../text-formatters')
const { BaseService } = require('..')
const documentation = `
<p>
Supply a unix timestamp in seconds to display the relative time from/to now
</p>
`
module.exports = class Date extends BaseService {
static category = 'other'
static route = { base: 'date', pattern: ':timestamp([0-9]+)' }
static examples = [
{
title: 'Relative date',
pattern: ':timestamp',
namedParams: { timestamp: '1540814400' },
staticPreview: this.render({ relativeDateString: '2 days ago' }),
keywords: ['time', 'countdown', 'countup', 'moment'],
documentation,
},
]
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),
})
}
}