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()