You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this is a compromise for space. it will show seconds up to 119, and then 2 minutes. this avoids renderings that are incorrect, like "1 minutes ago", and awkward, like "1 minute(s) ago". 135 bytes is too short to handle singular/plural...
I'd prefer adding the singular/plurar, which adds just a couple of bytes, but from an aesthetic pov it seems worth it? No? (This also fixes the 60seconds vs. 1minute thing as mentioned by @tsenart)
andy
function(
a, // a Date object
b, // placeholder
c // placeholder
){
for ( // whittle the date down to biggest unit
b = [ // an array containing the
1e3, // ms in a second,
60, // seconds in a minute,
60, // minutes in an hour, and
24 // hours in a day.
],
a = new Date - a, // get ms since date passed.
c = 0; // initialize the cursor.
a >= b[c]; // while the time left exceeds the current unit,
a /= b[c++] // divide the time by the unit and increment.
);
return ~ a + // the rounded remaining unit + // <- had to put a space between the two tildes to avoid display-problems in this text field
" " + // a space + the unit name, which we get by
"m0second0minute0hour0day" // taking a 0-delimited string of names
.split(0) // splitting it by 0, and
[c] + // taking the final cursor, +
( ~a > 1 ? "s ": "") + //adding singular/plurar is worth the couple of bytes
" ago" // and "ago"
}
//Please note I had to put a space between the rounding operators, since they triggered a strike-through
Very well done! One question though... is it supposed to show 60 seconds ago instead of 1 minute ago?