mirror of https://github.com/espruino/BangleApps
Fix date_utils if timezone is 12.
https://forum.espruino.com/conversations/387709/#comment17024817pull/2834/head
parent
b0ccc6c678
commit
5ae91b90b0
|
@ -8,7 +8,7 @@
|
||||||
// - 0/undefined --> Sunday
|
// - 0/undefined --> Sunday
|
||||||
// - 1 --> Monday
|
// - 1 --> Monday
|
||||||
// but you can start the week from any day if you need it.
|
// but you can start the week from any day if you need it.
|
||||||
//
|
//
|
||||||
// Some functions have an "abbreviated" parameter.
|
// Some functions have an "abbreviated" parameter.
|
||||||
// It supports the following 3 values:
|
// It supports the following 3 values:
|
||||||
// - 0/undefined --> get the full value, without abbreviation (eg.: "Monday", "January", etc.)
|
// - 0/undefined --> get the full value, without abbreviation (eg.: "Monday", "January", etc.)
|
||||||
|
@ -22,12 +22,12 @@
|
||||||
* @returns The localized name of the i-th day of the week
|
* @returns The localized name of the i-th day of the week
|
||||||
*/
|
*/
|
||||||
exports.dow = (i, abbreviated) => {
|
exports.dow = (i, abbreviated) => {
|
||||||
var dow = require("locale").dow(new Date(((i || 0) + 3.5) * 86400000), abbreviated).slice(0, (abbreviated == 2) ? 1 : 100);
|
var dow = require("locale").dow({getDay:()=>(i|0)%7}, abbreviated).slice(0, (abbreviated == 2) ? 1 : 100);
|
||||||
return abbreviated == 2 ? dow.toUpperCase() : dow;
|
return abbreviated == 2 ? dow.toUpperCase() : dow;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {int} firstDayOfWeek 0/undefined -> Sunday,
|
* @param {int} firstDayOfWeek 0/undefined -> Sunday,
|
||||||
* 1 -> Monday
|
* 1 -> Monday
|
||||||
* @param {int} abbreviated
|
* @param {int} abbreviated
|
||||||
* @returns All 7 days of the week (localized) as an array
|
* @returns All 7 days of the week (localized) as an array
|
||||||
|
@ -47,7 +47,7 @@ exports.dows = (firstDayOfWeek, abbreviated) => {
|
||||||
* @returns The localized name of the i-th month
|
* @returns The localized name of the i-th month
|
||||||
*/
|
*/
|
||||||
exports.month = (i, abbreviated) => {
|
exports.month = (i, abbreviated) => {
|
||||||
var month = require("locale").month(new Date((i - 0.5) * 2628000000), abbreviated).slice(0, (abbreviated == 2) ? 1 : 100);
|
var month = require("locale").month({getMonth:()=>(11+(i|0))%12}, abbreviated).slice(0, (abbreviated == 2) ? 1 : 100);
|
||||||
return abbreviated == 2 ? month.toUpperCase() : month;
|
return abbreviated == 2 ? month.toUpperCase() : month;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,8 +58,7 @@ exports.month = (i, abbreviated) => {
|
||||||
exports.months = (abbreviated) => {
|
exports.months = (abbreviated) => {
|
||||||
var months = [];
|
var months = [];
|
||||||
var locale = require("locale");
|
var locale = require("locale");
|
||||||
for (var i = 1; i <= 12; i++) {
|
for (var i = 0; i < 12; i++)
|
||||||
months.push(locale.month(new Date((i - 0.5) * 2628000000), abbreviated).slice(0, (abbreviated == 2) ? 1 : 100));
|
months.push(locale.month({getMonth:()=>i}, abbreviated).slice(0, (abbreviated == 2) ? 1 : 100));
|
||||||
}
|
|
||||||
return abbreviated == 2 ? months.map(month => month.toUpperCase()) : months;
|
return abbreviated == 2 ? months.map(month => month.toUpperCase()) : months;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue