Files
shields/services/date/date.service.js
Pierre-Yves B bc96f0e25f Example keywords validation (#2956)
This pull request closes #2551: making sure that the keywords don't already appear in the example's title.

I also added validation that checks that they are at least two characters long, as this is enforced by the homepage when type your search.
2019-02-13 13:14:12 -04:00

55 lines
1.1 KiB
JavaScript

'use strict'
const { formatRelativeDate } = require('../../lib/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 render({ relativeDateString }) {
return {
message: relativeDateString,
color: relativeDateString === 'invalid date' ? 'grey' : 'blue',
}
}
async handle({ timestamp }) {
return this.constructor.render({
relativeDateString: formatRelativeDate(timestamp),
})
}
// Metadata
static get defaultBadgeData() {
return { label: 'date' }
}
static get category() {
return 'other'
}
static get route() {
return {
base: 'date',
pattern: ':timestamp([0-9]+)',
}
}
static get examples() {
return [
{
title: 'Relative date',
pattern: ':timestamp',
namedParams: { timestamp: '1540814400' },
staticPreview: this.render({ relativeDateString: '2 days ago' }),
keywords: ['time', 'countdown', 'countup', 'moment'],
documentation,
},
]
}
}