JSFiddle - React, Tailwind, and code Playground
JavaScript
function FormattedDate() {
var args = Array.prototype.concat.apply([null], arguments);
var days = [ "Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday" ];
var months = ["January", "Feburary", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December"];
this.date = this.now = new (Function.prototype.bind.apply(Date, args));
this.day = this.days = this.date.getDate()+1;
this.dayName = this.dayname = this.day_name = days[this.date.getDay()-1];
this.dayShort = this.dayshort = this.day_short = this.dayName.slice(0,3);
this.month = this.months = this.mo = this.mos = this.date.getMonth()+1;
this.monthName = this.monthname = this.month_name = months[this.month-1];
this.monthShort = this.monthshort = this.month_short = this.monthName.slice(0,3);
this.year = this.years = this.yr = this.yrs = this.date.getFullYear();
this.hour = this.hours = this.hr = this.hrs = this.date.getHours();
this.minute = this.minutes = this.min = this.date.getMinutes();
this.second = this.seconds = this.sec = this.secs = this.date.getSeconds();
this.millisecond = this.milliseconds = this.ms = this.date.getMilliseconds();
this.time = this.epoch = this.date.getTime();
this.today = !!(new Date(new Date()-(24*60*60*1000)) < this.date);
}
FormattedDate.prototype = {
stringify: function stringify(entity, format) {
format = format || "MM/DD/YY HH:mm:ss";
if (entity) {
if (typeof this[entity] === 'string') return this[entity];
if (entity !== 'date') {
var num = this[entity];
if (num < 10) return "0"+num;
return ""+num;
}
}
if (this.today) {
var now = new FormattedDate();
var hoursAgo = (now.hour - this.hour);
...