forked from espruino/BangleApps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime_utils.min.js
More file actions
2 lines (2 loc) · 814 Bytes
/
Copy pathtime_utils.min.js
File metadata and controls
2 lines (2 loc) · 814 Bytes
1
2
function d(a){return{d:a.d||0,h:a.h||0,m:a.m||0,s:a.s||0}}exports.encodeTime=a=>{a=d(a);return 864E5*a.d+36E5*a.h+6E4*a.m+1E3*a.s};exports.decodeTime=a=>{if("number"!==typeof a)throw"Only a number can be decoded";var c=Math.floor(a/864E5);a-=864E5*c;var b=Math.floor(a/36E5);a-=36E5*b;var e=Math.floor(a/6E4);return{d:c,h:b,m:e,s:Math.floor((a-6E4*e)/1E3)}};exports.formatTime=a=>{a=d("object"===typeof a?a:exports.decodeTime(a));a.h+=24*a.d;return a.h+":"+("0"+a.m).substr(-2)};
exports.formatDuration=(a,c)=>{c=c||!1;var b="";a=d("object"===typeof a?a:exports.decodeTime(a));0<a.d&&(b+=a.d+"d ");0<a.h&&(b+=a.h+"h ");0<a.m&&(b+=a.m+"m ");0<a.s&&(b+=a.s+"s");b=b.trim();return c?b.replace(" ",""):b};exports.getCurrentTimeMillis=()=>{var a=new Date;return 1E3*(3600*a.getHours()+60*a.getMinutes()+a.getSeconds())}