From 98d185067bd34fde97985eef4d714c0b603ba311 Mon Sep 17 00:00:00 2001 From: olli Date: Fri, 1 Nov 2024 13:40:30 +0100 Subject: [PATCH] fix 1st day in month --- dabo/functions/currency_converter.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dabo/functions/currency_converter.sh b/dabo/functions/currency_converter.sh index 2d31fc3..b5fdfce 100644 --- a/dabo/functions/currency_converter.sh +++ b/dabo/functions/currency_converter.sh @@ -39,7 +39,7 @@ function currency_converter { fi # get current date if none given - [ -z "$f_currency_date" ] && printf -v f_currency_date '%(%Y-%m-%d %H:%M:%S)T' + [ -z "$f_currency_date" ] && printf -v f_currency_date '%(%Y-%m-%d.%H:%M:%S)T' # rate per minute f_currency_date_minute=$(date -d "${f_currency_date}" "+%Y-%m-%d.%H:%M") @@ -51,7 +51,13 @@ function currency_converter { f_currency_date_day=$(date -d "${f_currency_date}" "+%Y-%m-%d") # month failback - f_currency_date_month=$(date -d "${f_currency_date}" "+%Y-%m") + if [ $(date -d "${f_currency_date}" "+%d") = "01" ] + then + # on first day in month use month before because no date from current month + f_currency_date_month=$(date -d "${f_currency_date} yesterday" "+%Y-%m") + else + f_currency_date_month=$(date -d "${f_currency_date}" "+%Y-%m") + fi # path to history files for the converting rate [ -d asset-histories ] || mkdir asset-histories