1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

modify: fix test and logic

This commit is contained in:
sota1235
2016-12-22 12:27:37 +09:00
parent c11bd9e7eb
commit 74068eaa3d
2 changed files with 7 additions and 58 deletions

View File

@@ -1,36 +1,18 @@
/**
* @fileoverview Formatting date string.
*/
/** @var {Array} */
const monthMapings = [
'Jan.', 'Feb.', 'Mar.', 'Apr.', 'May', 'Jun.',
'Jul.', 'Aug.', 'Sep.', 'Oct.', 'Nov.', 'Dec.',
];
import moment from 'moment';
/**
* @description Return date string. For example, 'Sep.9, 2016 12:00'.
* @param {Date}
* @param {mixed}
* @return {string}
*/
export function getLastUpdated(date) {
if (!(date instanceof Date)) {
throw Error('Invalid argument. Only instance of Date Object');
const m = moment(date)
if (!m.isValid()) {
throw Error('Invalid argument.');
}
const year = date.getFullYear();
const month = monthMapings[date.getMonth()];
const day = date.getDate();
let hour = date.getHours();
let minute = date.getMinutes();
if (hour < 10) {
hour = `0${hour}`;
}
if (minute < 10) {
minute = `0${minute}`;
}
return `${month}${day}, ${year} ${hour}:${minute}`;
return m.format('MMM D, gggg H:mm')
}