2019-11-25 00:26:19 +11:00
|
|
|
'use strict'
|
2018-01-28 23:22:43 +11:00
|
|
|
//日付パーサー
|
|
|
|
function date(str, datetype) {
|
|
|
|
if (datetype == "relative") {
|
|
|
|
return '<time class="timeago" datetime="' + str + '"></time>';
|
|
|
|
} else {
|
|
|
|
var date = new Date(str);
|
|
|
|
if (datetype == "unix") {
|
|
|
|
var unixm = date.getTime();
|
|
|
|
return Math.floor(unixm / 1000);
|
|
|
|
}
|
|
|
|
var now = new Date();
|
|
|
|
var month = date.getMonth() + 1;
|
|
|
|
if (date.getMinutes() < 10) {
|
|
|
|
var min = "0" + date.getMinutes();
|
|
|
|
} else {
|
|
|
|
var min = date.getMinutes();
|
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
var sec = null;
|
2018-01-28 23:22:43 +11:00
|
|
|
if (date.getSeconds() < 10) {
|
2019-03-08 05:19:26 +11:00
|
|
|
sec = "0" + date.getSeconds();
|
2018-01-28 23:22:43 +11:00
|
|
|
} else {
|
2019-03-08 05:19:26 +11:00
|
|
|
sec = date.getSeconds();
|
2018-01-28 23:22:43 +11:00
|
|
|
}
|
|
|
|
if (datetype == "full") {
|
2018-05-26 02:37:35 +10:00
|
|
|
var ret = date.getFullYear() + "/" + month + "/" + date.getDate() + "/ " +
|
2018-01-28 23:22:43 +11:00
|
|
|
date.getHours() + ":" + min + ":" + sec;
|
|
|
|
}
|
|
|
|
if (date.getFullYear() == now.getFullYear()) {
|
|
|
|
if (date.getMonth() == now.getMonth()) {
|
|
|
|
if (date.getDate() == now.getDate()) {
|
|
|
|
if (datetype == "medium") {
|
|
|
|
var ret = '<time class="timeago" datetime="' + str + '"></time>';
|
|
|
|
} else {
|
|
|
|
var ret = date.getHours() + ":" + min + ":" + sec;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2018-05-26 02:37:35 +10:00
|
|
|
var ret = month + "/" + date.getDate() + " " + date.getHours() + ":" +
|
2018-01-28 23:22:43 +11:00
|
|
|
min + ":" + sec;
|
|
|
|
}
|
|
|
|
} else {
|
2018-05-26 02:37:35 +10:00
|
|
|
var ret = month + "/" + date.getDate() + " " + date.getHours() + ":" + min +
|
2018-01-28 23:22:43 +11:00
|
|
|
":" + sec;
|
|
|
|
}
|
|
|
|
} else {
|
2018-05-26 02:37:35 +10:00
|
|
|
var ret = date.getFullYear() + "/" + month + "/" + date.getDate() + " " +
|
2018-01-28 23:22:43 +11:00
|
|
|
date.getHours() + ":" + min + ":" + sec;
|
|
|
|
}
|
|
|
|
if (datetype == "double") {
|
|
|
|
return '<time class="timeago" datetime="' + str + '"></time>/' + ret;
|
|
|
|
} else {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//特殊フォーマット(インスタンス情報で利用)
|
|
|
|
function crat(str) {
|
|
|
|
var date = new Date(str);
|
2019-05-19 17:39:30 +10:00
|
|
|
var mnt = null;
|
|
|
|
if (date.getMonth() < 9) {
|
|
|
|
mnt = "0" + (date.getMonth() + 1);
|
|
|
|
} else {
|
|
|
|
mnt = date.getMonth() + 1;
|
2019-02-01 03:30:25 +11:00
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
if (date.getDate() < 10) {
|
|
|
|
var dat = "0" + date.getDate();
|
|
|
|
} else {
|
|
|
|
var dat = date.getDate();
|
2019-02-01 03:30:25 +11:00
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
if (date.getHours() < 10) {
|
|
|
|
var hrs = "0" + date.getHours();
|
|
|
|
} else {
|
|
|
|
var hrs = date.getHours();
|
2019-02-01 03:30:25 +11:00
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
if (date.getMinutes() < 10) {
|
|
|
|
var mns = "0" + date.getMinutes();
|
|
|
|
} else {
|
|
|
|
var mns = date.getMinutes();
|
2019-02-01 03:30:25 +11:00
|
|
|
}
|
2019-05-19 17:39:30 +10:00
|
|
|
if (date.getSeconds() < 10) {
|
|
|
|
var sec = "0" + date.getSeconds();
|
|
|
|
} else {
|
|
|
|
var sec = date.getSeconds();
|
2019-02-01 03:30:25 +11:00
|
|
|
}
|
2018-01-28 23:22:43 +11:00
|
|
|
format_str = 'YYYY-MM-DD hh:mm:ss';
|
|
|
|
format_str = format_str.replace(/YYYY/g, date.getFullYear());
|
2019-02-01 03:30:25 +11:00
|
|
|
format_str = format_str.replace(/MM/g, mnt);
|
|
|
|
format_str = format_str.replace(/DD/g, dat);
|
|
|
|
format_str = format_str.replace(/hh/g, hrs);
|
|
|
|
format_str = format_str.replace(/mm/g, mns);
|
|
|
|
format_str = format_str.replace(/ss/g, sec);
|
2018-01-28 23:22:43 +11:00
|
|
|
|
|
|
|
return format_str;
|
|
|
|
}
|