Add calendar.get_total_days_from_date

master
Wuzzy 2020-08-28 15:31:13 +02:00
parent 5cdfac7e3a
commit 980f3b9798
2 changed files with 16 additions and 0 deletions

7
API.md
View File

@ -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.

View File

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