From 980f3b97982db4a6507764f2bf9da4e8e26d820a Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 28 Aug 2020 15:31:13 +0200 Subject: [PATCH] Add calendar.get_total_days_from_date --- API.md | 7 +++++++ init.lua | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/API.md b/API.md index 439b7fd..b034932 100644 --- a/API.md +++ b/API.md @@ -66,6 +66,13 @@ Returns 4 values: days, months, years and days in year (in that order) if `false`, use cardinal numbers default: false +### `calendar.get_total_days_from_date(days, months, years, is_ordinal)` +Given a date, returns the total number of elapsed days (cardinal number). + +* `days`/`months`/`years`: Date +* `is_ordinal`: If `true`, date is interpreted as ordinal numbers, otherwise + it is interpreted as cardinal numbers (default: `false`) + ## `calendar.get_weekday(total_days)` Returns cardinal weekday number for given day. diff --git a/init.lua b/init.lua index 697b615..f5ac17e 100644 --- a/init.lua +++ b/init.lua @@ -143,6 +143,15 @@ calendar.get_date = function(total_days, ordinal) return d, m, y, j end +calendar.get_total_days_from_date = function(days, months, years, is_ordinal) + if is_ordinal then + days = days - 1 + months = months - 1 + years = years - 1 + end + return years * calendar.YEAR_DAYS + months * calendar.MONTH_DAYS + days +end + calendar.get_date_string = function(format, total_days) if not total_days then total_days = minetest.get_day_count()