fix issue with delivery year in apple widget

Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
This commit is contained in:
Benny Samir Hierl 2021-01-01 15:26:32 +01:00
parent 19df5daeda
commit 0ca8d417f0
No known key found for this signature in database
GPG key ID: 69DE3C3C097DB7F7

View file

@ -1,7 +1,7 @@
// Variables used by Scriptable. // Variables used by Scriptable.
// These must be at the very top of the file. Do not edit. // These must be at the very top of the file. Do not edit.
// icon-color: deep-blue; icon-glyph: shopping-cart; // icon-color: deep-blue; icon-glyph: shopping-cart;
// Version 1.1.4 // Version 1.1.5
const cacheMinutes = 60 * 2 const cacheMinutes = 60 * 2
const today = new Date() const today = new Date()
@ -101,7 +101,7 @@ const parseLongDate = (stringDate) => {
const m = stringDate.match(/([\w]+)[\s]([\d]{1,2}),[\s]([0-9]{4})/) const m = stringDate.match(/([\w]+)[\s]([\d]{1,2}),[\s]([0-9]{4})/)
return new Date(m[3], months[m[1]], m[2]) return new Date(m[3], months[m[1]], m[2])
} }
const parseShortDate = (stringDate, orderMonth) => { const parseShortDate = (stringDate, orderDate) => {
const months = { const months = {
'Jan': 0, 'Jan': 0,
'Feb': 1, 'Feb': 1,
@ -129,11 +129,11 @@ const parseShortDate = (stringDate, orderMonth) => {
} }
} }
let year = new Date().getFullYear() let deliveryDate = new Date((new Date().getFullYear()), months[m[2]], m[1])
if (months[m[2]] < orderMonth) { if (deliveryDate < orderDate) {
year += 1 deliveryDate.setFullYear(deliveryDate.getFullYear() + 1)
} }
return new Date(year, months[m[2]], m[1]) return deliveryDate
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
function creatProgress(total, havegone) { function creatProgress(total, havegone) {
@ -277,7 +277,7 @@ if (!orderDetails) {
const orderDate = parseLongDate(orderDetails['orderDetail']['orderHeader']['d']['orderPlacedDate']) const orderDate = parseLongDate(orderDetails['orderDetail']['orderHeader']['d']['orderPlacedDate'])
let deliveryDate = null let deliveryDate = null
try { try {
deliveryDate = parseShortDate(itemDetails['d']['deliveryDate'], orderDate.getMonth()) deliveryDate = parseShortDate(itemDetails['d']['deliveryDate'], orderDate)
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }