From 2e5e3ce0609aef4ca0de22ba95455e16839781e9 Mon Sep 17 00:00:00 2001 From: Sergey Shorokhov Date: Thu, 1 Jul 2021 11:51:24 +0300 Subject: [PATCH] Add month and year support to get_time_length() (#969) * Add RU * Add EN * Add DE * Add SR * Add BP * Add HU * Add SECONDS_IN_MONTH & timeunit_months * Add months for API description * Add SECONDS_IN_YEAR & timeunit_years * fix typo * Add FR --- plugins/include/time.inc | 24 +++++++++++++++++++++--- plugins/lang/time.txt | 30 +++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/plugins/include/time.inc b/plugins/include/time.inc index 34b91f65..286ccf09 100644 --- a/plugins/include/time.inc +++ b/plugins/include/time.inc @@ -24,6 +24,8 @@ enum timeunit_hours, timeunit_days, timeunit_weeks, + timeunit_months, + timeunit_years, }; /* Seconds in each time unit */ @@ -31,6 +33,8 @@ enum #define SECONDS_IN_HOUR 3600 #define SECONDS_IN_DAY 86400 #define SECONDS_IN_WEEK 604800 +#define SECONDS_IN_MONTH 2592000 +#define SECONDS_IN_YEAR 31536000 /** * Stock by Brad. @@ -39,7 +43,7 @@ enum * * @param id The player whose language the length should be translated to * @param unitCnt The number of time units you want translated into verbose text - * @param type The type of unit (i.e. seconds, minutes, hours, days, weeks) that you are passing in + * @param type The type of unit (i.e. seconds, minutes, hours, days, weeks, months, years) that you are passing in * @param output The variable you want the verbose text to be placed in * @param outputLen The length of the output variable * @@ -50,7 +54,7 @@ stock get_time_length(id, unitCnt, type, output[], outputLen) if (unitCnt > 0) { // determine the number of each time unit there are - new weekCnt = 0, dayCnt = 0, hourCnt = 0, minuteCnt = 0, secondCnt = 0; + new yearCnt = 0, monthCnt = 0, weekCnt = 0, dayCnt = 0, hourCnt = 0, minuteCnt = 0, secondCnt = 0; switch (type) { @@ -59,8 +63,16 @@ stock get_time_length(id, unitCnt, type, output[], outputLen) case timeunit_hours: secondCnt = unitCnt * SECONDS_IN_HOUR; case timeunit_days: secondCnt = unitCnt * SECONDS_IN_DAY; case timeunit_weeks: secondCnt = unitCnt * SECONDS_IN_WEEK; + case timeunit_months: secondCnt = unitCnt * SECONDS_IN_MONTH; + case timeunit_years: secondCnt = unitCnt * SECONDS_IN_YEAR; } + yearCnt = secondCnt / SECONDS_IN_YEAR; + secondCnt -= (yearCnt * SECONDS_IN_YEAR); + + monthCnt = secondCnt / SECONDS_IN_MONTH; + secondCnt -= (monthCnt * SECONDS_IN_MONTH); + weekCnt = secondCnt / SECONDS_IN_WEEK; secondCnt -= (weekCnt * SECONDS_IN_WEEK); @@ -75,8 +87,12 @@ stock get_time_length(id, unitCnt, type, output[], outputLen) // translate the unit counts into verbose text new maxElementIdx = -1; - new timeElement[5][33]; + new timeElement[7][33]; + if (yearCnt > 0) + format(timeElement[++maxElementIdx], charsmax(timeElement[]), "%i %L", yearCnt, id, (yearCnt == 1) ? "TIME_ELEMENT_YEAR" : "TIME_ELEMENT_YEARS"); + if (monthCnt > 0) + format(timeElement[++maxElementIdx], charsmax(timeElement[]), "%i %L", monthCnt, id, (monthCnt == 1) ? "TIME_ELEMENT_MONTH" : "TIME_ELEMENT_MONTHS"); if (weekCnt > 0) format(timeElement[++maxElementIdx], charsmax(timeElement[]), "%i %L", weekCnt, id, (weekCnt == 1) ? "TIME_ELEMENT_WEEK" : "TIME_ELEMENT_WEEKS"); if (dayCnt > 0) @@ -95,6 +111,8 @@ stock get_time_length(id, unitCnt, type, output[], outputLen) case 2: formatex(output, outputLen, "%s, %s %L %s", timeElement[0], timeElement[1], id, "TIME_ELEMENT_AND", timeElement[2]); case 3: formatex(output, outputLen, "%s, %s, %s %L %s", timeElement[0], timeElement[1], timeElement[2], id, "TIME_ELEMENT_AND", timeElement[3]); case 4: formatex(output, outputLen, "%s, %s, %s, %s %L %s", timeElement[0], timeElement[1], timeElement[2], timeElement[3], id, "TIME_ELEMENT_AND", timeElement[4]); + case 5: formatex(output, outputLen, "%s, %s, %s, %s, %s %L %s", timeElement[0], timeElement[1], timeElement[2], timeElement[3], timeElement[4], id, "TIME_ELEMENT_AND", timeElement[5]); + case 6: formatex(output, outputLen, "%s, %s, %s, %s, %s, %s %L %s", timeElement[0], timeElement[1], timeElement[2], timeElement[3], timeElement[4], timeElement[5], id, "TIME_ELEMENT_AND", timeElement[6]); } } } diff --git a/plugins/lang/time.txt b/plugins/lang/time.txt index 10909c8c..b610c58e 100644 --- a/plugins/lang/time.txt +++ b/plugins/lang/time.txt @@ -9,6 +9,10 @@ TIME_ELEMENT_DAY = day TIME_ELEMENT_DAYS = days TIME_ELEMENT_WEEK = week TIME_ELEMENT_WEEKS = weeks +TIME_ELEMENT_MONTH = month +TIME_ELEMENT_MONTHS = months +TIME_ELEMENT_YEAR = year +TIME_ELEMENT_YEARS = years TIME_ELEMENT_PERMANENTLY = permanently TIME_ELEMENT_AND = and @@ -23,6 +27,10 @@ TIME_ELEMENT_DAY = Tag TIME_ELEMENT_DAYS = Tage TIME_ELEMENT_WEEK = Woche TIME_ELEMENT_WEEKS = Wochen +TIME_ELEMENT_MONTH = Monat +TIME_ELEMENT_MONTHS = Monate +TIME_ELEMENT_YEAR = Jahr +TIME_ELEMENT_YEARS = Jahre TIME_ELEMENT_PERMANENTLY = permanent TIME_ELEMENT_AND = und @@ -37,6 +45,10 @@ TIME_ELEMENT_DAY = dan TIME_ELEMENT_DAYS = dani TIME_ELEMENT_WEEK = nedelja TIME_ELEMENT_WEEKS = nedelje +TIME_ELEMENT_MONTH = mesec +TIME_ELEMENT_MONTHS = meseci +TIME_ELEMENT_YEAR = godina +TIME_ELEMENT_YEARS = godine TIME_ELEMENT_PERMANENTLY = za stalno TIME_ELEMENT_AND = i @@ -65,7 +77,11 @@ TIME_ELEMENT_DAY = jour TIME_ELEMENT_DAYS = jours TIME_ELEMENT_WEEK = semaine TIME_ELEMENT_WEEKS = semaines -TIME_ELEMENT_PERMANENTLY = a vie (permanent) +TIME_ELEMENT_MONTH = mois +TIME_ELEMENT_MONTHS = mois +TIME_ELEMENT_YEAR = année +TIME_ELEMENT_YEARS = années +TIME_ELEMENT_PERMANENTLY = à vie (permanent) TIME_ELEMENT_AND = et [tr] @@ -107,6 +123,10 @@ TIME_ELEMENT_DAY = dia TIME_ELEMENT_DAYS = dias TIME_ELEMENT_WEEK = semana TIME_ELEMENT_WEEKS = semanas +TIME_ELEMENT_MONTH = mês +TIME_ELEMENT_MONTHS = meses +TIME_ELEMENT_YEAR = ano +TIME_ELEMENT_YEARS = anos TIME_ELEMENT_PERMANENTLY = permanentemente TIME_ELEMENT_AND = e @@ -205,6 +225,10 @@ TIME_ELEMENT_DAY = nap TIME_ELEMENT_DAYS = nap TIME_ELEMENT_WEEK = hét TIME_ELEMENT_WEEKS = hét +TIME_ELEMENT_MONTH = hónap +TIME_ELEMENT_MONTHS = hónapok +TIME_ELEMENT_YEAR = év +TIME_ELEMENT_YEARS = évek TIME_ELEMENT_PERMANENTLY = végleges TIME_ELEMENT_AND = és @@ -289,6 +313,10 @@ TIME_ELEMENT_DAY = день TIME_ELEMENT_DAYS = дней TIME_ELEMENT_WEEK = неделя TIME_ELEMENT_WEEKS = недель +TIME_ELEMENT_MONTH = месяц +TIME_ELEMENT_MONTHS = месяца +TIME_ELEMENT_YEAR = год +TIME_ELEMENT_YEARS = лет TIME_ELEMENT_PERMANENTLY = навсегда TIME_ELEMENT_AND = и