mirror of https://github.com/espruino/BangleApps
Add date_utils lib (https://github.com/espruino/BangleApps/pull/1753)
parent
48f01ae708
commit
2e2275c262
|
@ -0,0 +1,39 @@
|
|||
/* Utility functions that use the 'locale' module so can produce text
|
||||
in the currently selected language. */
|
||||
|
||||
/** Return the day of the week (0=Sunday)
|
||||
short==0/undefined -> "Sunday"
|
||||
short==1 -> "Sun"
|
||||
*/
|
||||
exports.getDOW = (dow, short) => require("locale").dow({getDay:()=>dow},short);
|
||||
|
||||
/** Return the month (1=January)
|
||||
short==0/undefined -> "January"
|
||||
short==1 -> "Jan"
|
||||
*/
|
||||
exports.getMonth = (month, short) => require("locale").month({getMonth:()=>month-1},short);
|
||||
|
||||
/** Return all 7 days of the week as an array ["Sunday","Monday",...].
|
||||
short==0/undefined -> ["Sunday",...
|
||||
short==1 -> ["Sun",...
|
||||
short==2 -> ["S",...
|
||||
*/
|
||||
exports.getDOWs = (short) => {
|
||||
var locale = require("locale");
|
||||
var days = [];
|
||||
for (var i=0;i<7;i++)
|
||||
days.push(locale.dow({getDay:()=>i},short).slice(0,(short==2)?1:100));
|
||||
return days;
|
||||
}
|
||||
|
||||
/** Return all 12 months as an array ["January","February",...]
|
||||
short==0/undefined -> ["January",...
|
||||
short==1 -> ["Jan",...
|
||||
*/
|
||||
exports.getMonths = (short) => {
|
||||
var locale = require("locale");
|
||||
var months = [];
|
||||
for (var i=0;i<12;i++)
|
||||
months.push(locale.month({getMonth:()=>i},short));
|
||||
return months;
|
||||
}
|
Loading…
Reference in New Issue