@speechkit/speechkit-audio-player
Version:
A web player component that can play audio from https://speechkit.io
37 lines (30 loc) • 925 B
JavaScript
const MONTH_NAMES = [
"January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December"
]
const SHORT_MONTH_NAMES = [
"Jan", "Feb", "Mar",
"Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct",
"Nov", "Dec"
]
const addAdditionalZero = val => (
`0${val}`.slice(-2)
)
export const formatDate = (date, withShortNames = false, lang) => {
const dateObj = new Date(date)
const day = dateObj.getDate()
const monthIndex = dateObj.getMonth()
const year = dateObj.getFullYear()
const months = withShortNames ? SHORT_MONTH_NAMES : MONTH_NAMES
return ['ru', 'de'].includes(lang)
? ([day, monthIndex + 1].map(item => addAdditionalZero(item))).concat([year]).join('.')
: `${months[monthIndex]} ${day}, ${year}`
}
export const addDays = (date, days) => {
const result = new Date(date)
result.setDate(result.getDate() + days)
return result
}