Fix indentation to use 2 spaces in multiple files

This commit is contained in:
NoM0Re
2025-02-09 21:08:57 +01:00
parent 75eb0fd437
commit 4f98ae597f
3 changed files with 330 additions and 330 deletions
+30 -30
View File
@@ -45,47 +45,47 @@ function tIndexOf(tbl, item)
end end
function TableHasAnyEntries(tbl) function TableHasAnyEntries(tbl)
if tbl and type(tbl) == "table" then if tbl and type(tbl) == "table" then
for _ in pairs(tbl) do for _ in pairs(tbl) do
return true return true
end end
end end
return false return false
end end
function tAppendAll(table, addedArray) function tAppendAll(table, addedArray)
for i, element in ipairs(addedArray) do for i, element in ipairs(addedArray) do
tinsert(table, element); tinsert(table, element);
end end
end end
function MergeTable(t1, t2) function MergeTable(t1, t2)
local merged = {} local merged = {}
for k, v in pairs(t1) do for k, v in pairs(t1) do
merged[k] = v merged[k] = v
end end
for k, v in pairs(t2) do for k, v in pairs(t2) do
merged[k] = v merged[k] = v
end end
return merged return merged
end end
function tCompare(t1, t2) function tCompare(t1, t2)
for k, v in pairs(t1) do for k, v in pairs(t1) do
if type(v) == "table" and type(t2[k]) == "table" then if type(v) == "table" and type(t2[k]) == "table" then
if not tCompare(v, t2[k]) then if not tCompare(v, t2[k]) then
return false return false
end end
elseif t2[k] ~= v then elseif t2[k] ~= v then
return false return false
end
end end
for k in pairs(t2) do end
if t1[k] == nil then for k in pairs(t2) do
return false if t1[k] == nil then
end return false
end end
return true end
return true
end end
function IsInGroup() function IsInGroup()
+1 -1
View File
@@ -133,7 +133,7 @@ if LibGroupTalents then
end end
end end
end end
end end
else else
function Private.LibGroupTalentsWrapper.Register(f) end function Private.LibGroupTalentsWrapper.Register(f) end
function Private.LibGroupTalentsWrapper.SpecForUnit(unit) return nil end function Private.LibGroupTalentsWrapper.SpecForUnit(unit) return nil end
+299 -299
View File
@@ -18,47 +18,47 @@ local SECONDS_PER_MONTH = 30 * SECONDS_PER_DAY;
local SECONDS_PER_YEAR = 12 * SECONDS_PER_MONTH; local SECONDS_PER_YEAR = 12 * SECONDS_PER_MONTH;
function SecondsToMinutes(seconds) function SecondsToMinutes(seconds)
return seconds / SECONDS_PER_MIN; return seconds / SECONDS_PER_MIN;
end end
function MinutesToSeconds(minutes) function MinutesToSeconds(minutes)
return minutes * SECONDS_PER_MIN; return minutes * SECONDS_PER_MIN;
end end
function HasTimePassed(testTime, amountOfTime) function HasTimePassed(testTime, amountOfTime)
return ((time() - testTime) >= amountOfTime); return ((time() - testTime) >= amountOfTime);
end end
SecondsFormatter = {}; SecondsFormatter = {};
SecondsFormatterConstants = SecondsFormatterConstants =
{ {
ZeroApproximationThreshold = 0, ZeroApproximationThreshold = 0,
ConvertToLower = true, ConvertToLower = true,
DontConvertToLower = false, DontConvertToLower = false,
RoundUpLastUnit = true, RoundUpLastUnit = true,
DontRoundUpLastUnit = false, DontRoundUpLastUnit = false,
} }
SecondsFormatter.Abbreviation = SecondsFormatter.Abbreviation =
{ {
None = 1, -- seconds, minutes, hours... None = 1, -- seconds, minutes, hours...
Truncate = 2, -- sec, min, hr... Truncate = 2, -- sec, min, hr...
OneLetter = 3, -- s, m, h... OneLetter = 3, -- s, m, h...
} }
SecondsFormatter.Interval = { SecondsFormatter.Interval = {
Seconds = 1, Seconds = 1,
Minutes = 2, Minutes = 2,
Hours = 3, Hours = 3,
Days = 4, Days = 4,
} }
SecondsFormatter.IntervalDescription = { SecondsFormatter.IntervalDescription = {
[SecondsFormatter.Interval.Seconds] = {seconds = 1, formatString = { L["D_SECONDS"], L["SECONDS_ABBR"], L["SECOND_ONELETTER_ABBR"]}}, [SecondsFormatter.Interval.Seconds] = {seconds = 1, formatString = { L["D_SECONDS"], L["SECONDS_ABBR"], L["SECOND_ONELETTER_ABBR"]}},
[SecondsFormatter.Interval.Minutes] = {seconds = SECONDS_PER_MIN, formatString = {L["D_MINUTES"], L["MINUTES_ABBR"], L["MINUTE_ONELETTER_ABBR"]}}, [SecondsFormatter.Interval.Minutes] = {seconds = SECONDS_PER_MIN, formatString = {L["D_MINUTES"], L["MINUTES_ABBR"], L["MINUTE_ONELETTER_ABBR"]}},
[SecondsFormatter.Interval.Hours] = {seconds = SECONDS_PER_HOUR, formatString = {L["D_HOURS"], L["HOURS_ABBR"], L["HOUR_ONELETTER_ABBR"]}}, [SecondsFormatter.Interval.Hours] = {seconds = SECONDS_PER_HOUR, formatString = {L["D_HOURS"], L["HOURS_ABBR"], L["HOUR_ONELETTER_ABBR"]}},
[SecondsFormatter.Interval.Days] = {seconds = SECONDS_PER_DAY, formatString = {L["D_DAYS"], L["DAYS_ABBR"], L["DAY_ONELETTER_ABBR"]}}, [SecondsFormatter.Interval.Days] = {seconds = SECONDS_PER_DAY, formatString = {L["D_DAYS"], L["DAYS_ABBR"], L["DAY_ONELETTER_ABBR"]}},
} }
--[[ Seconds formatter to standardize representations of seconds. When adding a new formatter --[[ Seconds formatter to standardize representations of seconds. When adding a new formatter
@@ -72,42 +72,42 @@ SecondsFormatterMixin = {}
-- roundUpLastUnit: determines if the last unit in the output format string is ceiled (floored by default). -- roundUpLastUnit: determines if the last unit in the output format string is ceiled (floored by default).
-- convertToLower: converts the format string to lowercase. -- convertToLower: converts the format string to lowercase.
function SecondsFormatterMixin:Init(approximationSeconds, defaultAbbreviation, roundUpLastUnit, convertToLower) function SecondsFormatterMixin:Init(approximationSeconds, defaultAbbreviation, roundUpLastUnit, convertToLower)
self:SetApproximationSeconds(approximationSeconds or 0); self:SetApproximationSeconds(approximationSeconds or 0);
self:SetMinInterval(SecondsFormatter.Interval.Seconds); self:SetMinInterval(SecondsFormatter.Interval.Seconds);
self:SetDefaultAbbreviation(defaultAbbreviation or SecondsFormatter.Abbreviation.None); self:SetDefaultAbbreviation(defaultAbbreviation or SecondsFormatter.Abbreviation.None);
self:SetCanRoundUpLastUnit(roundUpLastUnit or false); self:SetCanRoundUpLastUnit(roundUpLastUnit or false);
self:SetDesiredUnitCount(2); self:SetDesiredUnitCount(2);
self:SetStripIntervalWhitespace(false); self:SetStripIntervalWhitespace(false);
self:SetConvertToLower(convertToLower or false); self:SetConvertToLower(convertToLower or false);
end end
function SecondsFormatterMixin:SetStripIntervalWhitespace(strip) function SecondsFormatterMixin:SetStripIntervalWhitespace(strip)
self.stripIntervalWhitespace = strip; self.stripIntervalWhitespace = strip;
end end
function SecondsFormatterMixin:GetStripIntervalWhitespace() function SecondsFormatterMixin:GetStripIntervalWhitespace()
return self.stripIntervalWhitespace; return self.stripIntervalWhitespace;
end end
function SecondsFormatterMixin:SetConvertToLower(convertToLower) function SecondsFormatterMixin:SetConvertToLower(convertToLower)
self.convertToLower = convertToLower; self.convertToLower = convertToLower;
end end
function SecondsFormatterMixin:GetMaxInterval() function SecondsFormatterMixin:GetMaxInterval()
return #SecondsFormatter.IntervalDescription; return #SecondsFormatter.IntervalDescription;
end end
function SecondsFormatterMixin:GetIntervalDescription(interval) function SecondsFormatterMixin:GetIntervalDescription(interval)
return SecondsFormatter.IntervalDescription[interval]; return SecondsFormatter.IntervalDescription[interval];
end end
function SecondsFormatterMixin:GetIntervalSeconds(interval) function SecondsFormatterMixin:GetIntervalSeconds(interval)
local intervalDescription = self:GetIntervalDescription(interval); local intervalDescription = self:GetIntervalDescription(interval);
return intervalDescription and intervalDescription.seconds or nil; return intervalDescription and intervalDescription.seconds or nil;
end end
function SecondsFormatterMixin:CanApproximate(seconds) function SecondsFormatterMixin:CanApproximate(seconds)
return (seconds > 0 and seconds < self:GetApproximationSeconds()); return (seconds > 0 and seconds < self:GetApproximationSeconds());
end end
function SecondsFormatterMixin:SetDefaultAbbreviation(defaultAbbreviation) function SecondsFormatterMixin:SetDefaultAbbreviation(defaultAbbreviation)
@@ -115,352 +115,352 @@ function SecondsFormatterMixin:SetDefaultAbbreviation(defaultAbbreviation)
end end
function SecondsFormatterMixin:GetDefaultAbbreviation() function SecondsFormatterMixin:GetDefaultAbbreviation()
return self.defaultAbbreviation; return self.defaultAbbreviation;
end end
function SecondsFormatterMixin:SetApproximationSeconds(approximationSeconds) function SecondsFormatterMixin:SetApproximationSeconds(approximationSeconds)
self.approximationSeconds = approximationSeconds; self.approximationSeconds = approximationSeconds;
end end
function SecondsFormatterMixin:GetApproximationSeconds() function SecondsFormatterMixin:GetApproximationSeconds()
return self.approximationSeconds; return self.approximationSeconds;
end end
function SecondsFormatterMixin:SetCanRoundUpLastUnit(roundUpLastUnit) function SecondsFormatterMixin:SetCanRoundUpLastUnit(roundUpLastUnit)
self.roundUpLastUnit = roundUpLastUnit; self.roundUpLastUnit = roundUpLastUnit;
end end
function SecondsFormatterMixin:CanRoundUpLastUnit() function SecondsFormatterMixin:CanRoundUpLastUnit()
return self.roundUpLastUnit; return self.roundUpLastUnit;
end end
function SecondsFormatterMixin:SetDesiredUnitCount(unitCount) function SecondsFormatterMixin:SetDesiredUnitCount(unitCount)
self.unitCount = unitCount; self.unitCount = unitCount;
end end
function SecondsFormatterMixin:GetDesiredUnitCount(seconds) function SecondsFormatterMixin:GetDesiredUnitCount(seconds)
-- seconds ignored in base implementation, but instances of this mixin can override this function -- seconds ignored in base implementation, but instances of this mixin can override this function
return self.unitCount; return self.unitCount;
end end
function SecondsFormatterMixin:SetMinInterval(interval) function SecondsFormatterMixin:SetMinInterval(interval)
self.minInterval = interval; self.minInterval = interval;
end end
function SecondsFormatterMixin:GetMinInterval(seconds) function SecondsFormatterMixin:GetMinInterval(seconds)
-- seconds ignored in base implementation, but instances of this mixin can override this function -- seconds ignored in base implementation, but instances of this mixin can override this function
return self.minInterval; return self.minInterval;
end end
function SecondsFormatterMixin:GetFormatString(interval, abbreviation, convertToLower) function SecondsFormatterMixin:GetFormatString(interval, abbreviation, convertToLower)
local intervalDescription = self:GetIntervalDescription(interval); local intervalDescription = self:GetIntervalDescription(interval);
local formatString = intervalDescription.formatString[abbreviation]; local formatString = intervalDescription.formatString[abbreviation];
if convertToLower then if convertToLower then
formatString = formatString:lower(); formatString = formatString:lower();
end end
local strip = TIME_UTIL_WHITE_SPACE_STRIPPABLE and self:GetStripIntervalWhitespace(); local strip = TIME_UTIL_WHITE_SPACE_STRIPPABLE and self:GetStripIntervalWhitespace();
return strip and formatString:gsub(" ", "") or formatString; return strip and formatString:gsub(" ", "") or formatString;
end end
function SecondsFormatterMixin:FormatZero(abbreviation, toLower) function SecondsFormatterMixin:FormatZero(abbreviation, toLower)
local minInterval = self:GetMinInterval(seconds); local minInterval = self:GetMinInterval(seconds);
local formatString = self:GetFormatString(minInterval, abbreviation); local formatString = self:GetFormatString(minInterval, abbreviation);
return formatString:format(0); return formatString:format(0);
end end
function SecondsFormatterMixin:FormatMillseconds(millseconds, abbreviation) function SecondsFormatterMixin:FormatMillseconds(millseconds, abbreviation)
return self:Format(millseconds/1000, abbreviation); return self:Format(millseconds/1000, abbreviation);
end end
function SecondsFormatterMixin:Format(seconds, abbreviation) function SecondsFormatterMixin:Format(seconds, abbreviation)
if (seconds == nil) then if (seconds == nil) then
return ""; return "";
end end
seconds = math.ceil(seconds); seconds = math.ceil(seconds);
abbreviation = abbreviation or self:GetDefaultAbbreviation(); abbreviation = abbreviation or self:GetDefaultAbbreviation();
if (seconds <= 0) then if (seconds <= 0) then
return self:FormatZero(abbreviation); return self:FormatZero(abbreviation);
end end
local minInterval = self:GetMinInterval(seconds); local minInterval = self:GetMinInterval(seconds);
local maxInterval = self:GetMaxInterval(); local maxInterval = self:GetMaxInterval();
if (self:CanApproximate(seconds)) then if (self:CanApproximate(seconds)) then
local interval = math.max(minInterval, SecondsFormatter.Interval.Minutes); local interval = math.max(minInterval, SecondsFormatter.Interval.Minutes);
while (interval < maxInterval) do while (interval < maxInterval) do
local nextInterval = interval + 1; local nextInterval = interval + 1;
if (seconds > self:GetIntervalSeconds(nextInterval)) then if (seconds > self:GetIntervalSeconds(nextInterval)) then
interval = nextInterval; interval = nextInterval;
else else
break; break;
end end
end end
local formatString = self:GetFormatString(interval, abbreviation, self.convertToLower); local formatString = self:GetFormatString(interval, abbreviation, self.convertToLower);
local unit = formatString:format(math.ceil(seconds / self:GetIntervalSeconds(interval))); local unit = formatString:format(math.ceil(seconds / self:GetIntervalSeconds(interval)));
return string.format(L["LESS_THAN_OPERAND"], unit); return string.format(L["LESS_THAN_OPERAND"], unit);
end end
local output = ""; local output = "";
local appendedCount = 0; local appendedCount = 0;
local desiredCount = self:GetDesiredUnitCount(seconds); local desiredCount = self:GetDesiredUnitCount(seconds);
local convertToLower = self.convertToLower; local convertToLower = self.convertToLower;
local currentInterval = maxInterval; local currentInterval = maxInterval;
while ((appendedCount < desiredCount) and (currentInterval >= minInterval)) do while ((appendedCount < desiredCount) and (currentInterval >= minInterval)) do
local intervalDescription = self:GetIntervalDescription(currentInterval); local intervalDescription = self:GetIntervalDescription(currentInterval);
local intervalSeconds = intervalDescription.seconds; local intervalSeconds = intervalDescription.seconds;
if (seconds >= intervalSeconds) then if (seconds >= intervalSeconds) then
appendedCount = appendedCount + 1; appendedCount = appendedCount + 1;
if (output ~= "") then if (output ~= "") then
output = output..L["TIME_UNIT_DELIMITER"]; output = output..L["TIME_UNIT_DELIMITER"];
end end
local formatString = self:GetFormatString(currentInterval, abbreviation, convertToLower); local formatString = self:GetFormatString(currentInterval, abbreviation, convertToLower);
local quotient = seconds / intervalSeconds; local quotient = seconds / intervalSeconds;
if (quotient > 0) then if (quotient > 0) then
if (self:CanRoundUpLastUnit() and ((minInterval == currentInterval) or (appendedCount == desiredCount))) then if (self:CanRoundUpLastUnit() and ((minInterval == currentInterval) or (appendedCount == desiredCount))) then
output = output..formatString:format(math.ceil(quotient)); output = output..formatString:format(math.ceil(quotient));
else else
output = output..formatString:format(math.floor(quotient)); output = output..formatString:format(math.floor(quotient));
end end
else else
break; break;
end end
seconds = math.fmod(seconds, intervalSeconds); seconds = math.fmod(seconds, intervalSeconds);
end end
currentInterval = currentInterval - 1; currentInterval = currentInterval - 1;
end end
-- Return the zero format if an acceptable representation couldn't be formed. -- Return the zero format if an acceptable representation couldn't be formed.
if (output == "") then if (output == "") then
return self:FormatZero(abbreviation); return self:FormatZero(abbreviation);
end end
return output; return output;
end end
function ConvertSecondsToUnits(timestamp) function ConvertSecondsToUnits(timestamp)
timestamp = math.max(timestamp, 0); timestamp = math.max(timestamp, 0);
local days = math.floor(timestamp / SECONDS_PER_DAY); local days = math.floor(timestamp / SECONDS_PER_DAY);
timestamp = timestamp - (days * SECONDS_PER_DAY); timestamp = timestamp - (days * SECONDS_PER_DAY);
local hours = math.floor(timestamp / SECONDS_PER_HOUR); local hours = math.floor(timestamp / SECONDS_PER_HOUR);
timestamp = timestamp - (hours * SECONDS_PER_HOUR); timestamp = timestamp - (hours * SECONDS_PER_HOUR);
local minutes = math.floor(timestamp / SECONDS_PER_MIN); local minutes = math.floor(timestamp / SECONDS_PER_MIN);
timestamp = timestamp - (minutes * SECONDS_PER_MIN); timestamp = timestamp - (minutes * SECONDS_PER_MIN);
local seconds = math.floor(timestamp); local seconds = math.floor(timestamp);
local milliseconds = timestamp - seconds; local milliseconds = timestamp - seconds;
return { return {
days=days, days=days,
hours=hours, hours=hours,
minutes=minutes, minutes=minutes,
seconds=seconds, seconds=seconds,
milliseconds=milliseconds, milliseconds=milliseconds,
} }
end end
function SecondsToClock(seconds, displayZeroHours) function SecondsToClock(seconds, displayZeroHours)
local units = ConvertSecondsToUnits(seconds); local units = ConvertSecondsToUnits(seconds);
if units.hours > 0 or displayZeroHours then if units.hours > 0 or displayZeroHours then
return format(L["HOURS_MINUTES_SECONDS"], units.hours, units.minutes, units.seconds); return format(L["HOURS_MINUTES_SECONDS"], units.hours, units.minutes, units.seconds);
else else
return format(L["MINUTES_SECONDS"], units.minutes, units.seconds); return format(L["MINUTES_SECONDS"], units.minutes, units.seconds);
end end
end end
-- Deprecated. See SecondsFormatter for intended replacement -- Deprecated. See SecondsFormatter for intended replacement
function SecondsToTime(seconds, noSeconds, notAbbreviated, maxCount, roundUp) function SecondsToTime(seconds, noSeconds, notAbbreviated, maxCount, roundUp)
local time = ""; local time = "";
local count = 0; local count = 0;
local tempTime; local tempTime;
seconds = roundUp and math.ceil(seconds) or math.floor(seconds); seconds = roundUp and math.ceil(seconds) or math.floor(seconds);
maxCount = maxCount or 2; maxCount = maxCount or 2;
-- When limited to a single term, use a higher threshold of 1.5 min/hr/day. -- When limited to a single term, use a higher threshold of 1.5 min/hr/day.
-- If there are at least 2 terms, the higher threshold is unnecessary. -- If there are at least 2 terms, the higher threshold is unnecessary.
local threshold = maxCount > 1 and 1.0 or 1.5 local threshold = maxCount > 1 and 1.0 or 1.5
if ( seconds >= SECONDS_PER_DAY * threshold ) then if ( seconds >= SECONDS_PER_DAY * threshold ) then
count = count + 1; count = count + 1;
if ( count == maxCount and roundUp ) then if ( count == maxCount and roundUp ) then
tempTime = math.ceil(seconds / SECONDS_PER_DAY); tempTime = math.ceil(seconds / SECONDS_PER_DAY);
else else
tempTime = math.floor(seconds / SECONDS_PER_DAY); tempTime = math.floor(seconds / SECONDS_PER_DAY);
end end
if ( notAbbreviated ) then if ( notAbbreviated ) then
time = L["D_DAYS"]:format(tempTime); time = L["D_DAYS"]:format(tempTime);
else else
time = L["DAYS_ABBR"]:format(tempTime); time = L["DAYS_ABBR"]:format(tempTime);
end end
seconds = seconds % SECONDS_PER_DAY; seconds = seconds % SECONDS_PER_DAY;
end end
if ( count < maxCount and seconds >= SECONDS_PER_HOUR * threshold ) then if ( count < maxCount and seconds >= SECONDS_PER_HOUR * threshold ) then
count = count + 1; count = count + 1;
if ( time ~= "" ) then if ( time ~= "" ) then
time = time..L["TIME_UNIT_DELIMITER"]; time = time..L["TIME_UNIT_DELIMITER"];
end end
if ( count == maxCount and roundUp ) then if ( count == maxCount and roundUp ) then
tempTime = math.ceil(seconds / SECONDS_PER_HOUR); tempTime = math.ceil(seconds / SECONDS_PER_HOUR);
else else
tempTime = math.floor(seconds / SECONDS_PER_HOUR); tempTime = math.floor(seconds / SECONDS_PER_HOUR);
end end
if ( notAbbreviated ) then if ( notAbbreviated ) then
time = time..L["D_HOURS"]:format(tempTime); time = time..L["D_HOURS"]:format(tempTime);
else else
time = time..L["HOURS_ABBR"]:format(tempTime); time = time..L["HOURS_ABBR"]:format(tempTime);
end end
seconds = seconds % SECONDS_PER_HOUR; seconds = seconds % SECONDS_PER_HOUR;
end end
if ( count < maxCount and seconds >= SECONDS_PER_MIN * threshold ) then if ( count < maxCount and seconds >= SECONDS_PER_MIN * threshold ) then
count = count + 1; count = count + 1;
if ( time ~= "" ) then if ( time ~= "" ) then
time = time..L["TIME_UNIT_DELIMITER"]; time = time..L["TIME_UNIT_DELIMITER"];
end end
if ( count == maxCount and roundUp ) then if ( count == maxCount and roundUp ) then
tempTime = math.ceil(seconds / SECONDS_PER_MIN); tempTime = math.ceil(seconds / SECONDS_PER_MIN);
else else
tempTime = math.floor(seconds / SECONDS_PER_MIN); tempTime = math.floor(seconds / SECONDS_PER_MIN);
end end
if ( notAbbreviated ) then if ( notAbbreviated ) then
time = time..L["D_MINUTES"]:format(tempTime); time = time..L["D_MINUTES"]:format(tempTime);
else else
time = time..L["MINUTES_ABBR"]:format(tempTime); time = time..L["MINUTES_ABBR"]:format(tempTime);
end end
seconds = seconds % SECONDS_PER_MIN; seconds = seconds % SECONDS_PER_MIN;
end end
if ( count < maxCount and seconds > 0 and not noSeconds ) then if ( count < maxCount and seconds > 0 and not noSeconds ) then
if ( time ~= "" ) then if ( time ~= "" ) then
time = time..L["TIME_UNIT_DELIMITER"]; time = time..L["TIME_UNIT_DELIMITER"];
end end
if ( notAbbreviated ) then if ( notAbbreviated ) then
time = time..L["D_SECONDS"]:format(seconds); time = time..L["D_SECONDS"]:format(seconds);
else else
time = time..L["SECONDS_ABBR"]:format(seconds); time = time..L["SECONDS_ABBR"]:format(seconds);
end end
end end
return time; return time;
end end
-- Deprecated. See SecondsFormatter for intended replacement -- Deprecated. See SecondsFormatter for intended replacement
function MinutesToTime(mins, hideDays) function MinutesToTime(mins, hideDays)
local time = ""; local time = "";
local count = 0; local count = 0;
local tempTime; local tempTime;
-- only show days if hideDays is false -- only show days if hideDays is false
if ( mins > 1440 and not hideDays ) then if ( mins > 1440 and not hideDays ) then
tempTime = floor(mins / 1440); tempTime = floor(mins / 1440);
time = L["TIME_UNIT_DELIMITER"] .. format(L["DAYS_ABBR"], tempTime); time = L["TIME_UNIT_DELIMITER"] .. format(L["DAYS_ABBR"], tempTime);
mins = mins % 1440; mins = mins % 1440;
count = count + 1; count = count + 1;
end end
if ( mins > 60 ) then if ( mins > 60 ) then
tempTime = floor(mins / 60); tempTime = floor(mins / 60);
time = time .. L["TIME_UNIT_DELIMITER"] .. format(L["HOURS_ABBR"], tempTime); time = time .. L["TIME_UNIT_DELIMITER"] .. format(L["HOURS_ABBR"], tempTime);
mins = mins % 60; mins = mins % 60;
count = count + 1; count = count + 1;
end end
if ( count < 2 ) then if ( count < 2 ) then
tempTime = mins; tempTime = mins;
time = time .. L["TIME_UNIT_DELIMITER"] .. format(L["MINUTES_ABBR"], tempTime); time = time .. L["TIME_UNIT_DELIMITER"] .. format(L["MINUTES_ABBR"], tempTime);
count = count + 1; count = count + 1;
end end
return time; return time;
end end
-- Deprecated. See SecondsFormatter for intended replacement -- Deprecated. See SecondsFormatter for intended replacement
function SecondsToTimeAbbrev(seconds, thresholdOverride) function SecondsToTimeAbbrev(seconds, thresholdOverride)
local tempTime; local tempTime;
local threshold = 1.5; local threshold = 1.5;
if thresholdOverride then if thresholdOverride then
threshold = thresholdOverride; threshold = thresholdOverride;
end end
if ( seconds >= SECONDS_PER_DAY * threshold ) then if ( seconds >= SECONDS_PER_DAY * threshold ) then
tempTime = ceil(seconds / SECONDS_PER_DAY); tempTime = ceil(seconds / SECONDS_PER_DAY);
return L["DAY_ONELETTER_ABBR"], tempTime; return L["DAY_ONELETTER_ABBR"], tempTime;
end end
if ( seconds >= SECONDS_PER_HOUR * threshold ) then if ( seconds >= SECONDS_PER_HOUR * threshold ) then
tempTime = ceil(seconds / SECONDS_PER_HOUR); tempTime = ceil(seconds / SECONDS_PER_HOUR);
return L["HOUR_ONELETTER_ABBR"], tempTime; return L["HOUR_ONELETTER_ABBR"], tempTime;
end end
if ( seconds >= SECONDS_PER_MIN * threshold ) then if ( seconds >= SECONDS_PER_MIN * threshold ) then
tempTime = ceil(seconds / SECONDS_PER_MIN); tempTime = ceil(seconds / SECONDS_PER_MIN);
return L["MINUTE_ONELETTER_ABBR"], tempTime; return L["MINUTE_ONELETTER_ABBR"], tempTime;
end end
return L["SECOND_ONELETTER_ABBR"], seconds; return L["SECOND_ONELETTER_ABBR"], seconds;
end end
function FormatShortDate(day, month, year) function FormatShortDate(day, month, year)
local LOCALE_enGB = (GetLocale() == "enUS") or (GetLocale() == "enGB") local LOCALE_enGB = (GetLocale() == "enUS") or (GetLocale() == "enGB")
if (year) then if (year) then
if (LOCALE_enGB) then if (LOCALE_enGB) then
return L["SHORTDATE_EU"]:format(day, month, year); return L["SHORTDATE_EU"]:format(day, month, year);
else else
return L["SHORTDATE"]:format(day, month, year); return L["SHORTDATE"]:format(day, month, year);
end end
else else
if (LOCALE_enGB) then if (LOCALE_enGB) then
return L["SHORTDATENOYEAR_EU"]:format(day, month); return L["SHORTDATENOYEAR_EU"]:format(day, month);
else else
return L["SHORTDATENOYEAR"]:format(day, month); return L["SHORTDATENOYEAR"]:format(day, month);
end end
end end
end end
function BreakUpLargeNumbers(value) function BreakUpLargeNumbers(value)
local retString = ""; local retString = "";
if ( value < 1000 ) then if ( value < 1000 ) then
if ( (value - math.floor(value)) == 0) then if ( (value - math.floor(value)) == 0) then
return value; return value;
end end
local decimal = (math.floor(value*100)); local decimal = (math.floor(value*100));
retString = string.sub(decimal, 1, -3); retString = string.sub(decimal, 1, -3);
retString = retString..L["DECIMAL_SEPERATOR"]; retString = retString..L["DECIMAL_SEPERATOR"];
retString = retString..string.sub(decimal, -2); retString = retString..string.sub(decimal, -2);
return retString; return retString;
end
value = math.floor(value);
retString = value;
return retString;
end
function AbbreviateLargeNumbers(value)
local strLen = strlen(value);
local retString = value;
if ( strLen > 8 ) then
retString = string.sub(value, 1, -7)..L["SECOND_NUMBER_CAP"];
elseif ( strLen > 5 ) then
retString = string.sub(value, 1, -4)..L["FIRST_NUMBER_CAP"];
elseif (strLen > 3 ) then
retString = BreakUpLargeNumbers(value);
end end
value = math.floor(value);
retString = value;
return retString; return retString;
end end
function AbbreviateLargeNumbers(value)
local strLen = strlen(value);
local retString = value;
if ( strLen > 8 ) then
retString = string.sub(value, 1, -7)..L["SECOND_NUMBER_CAP"];
elseif ( strLen > 5 ) then
retString = string.sub(value, 1, -4)..L["FIRST_NUMBER_CAP"];
elseif (strLen > 3 ) then
retString = BreakUpLargeNumbers(value);
end
return retString;
end
NUMBER_ABBREVIATION_DATA = { NUMBER_ABBREVIATION_DATA = {
-- Order these from largest to smallest -- Order these from largest to smallest
-- (significandDivisor and fractionDivisor should multiply to be equal to breakpoint) -- (significandDivisor and fractionDivisor should multiply to be equal to breakpoint)
{ breakpoint = 10000000000000, abbreviation = L["FOURTH_NUMBER_CAP_NO_SPACE"], significandDivisor = 1000000000000, fractionDivisor = 1 }, { breakpoint = 10000000000000, abbreviation = L["FOURTH_NUMBER_CAP_NO_SPACE"], significandDivisor = 1000000000000, fractionDivisor = 1 },
{ breakpoint = 1000000000000, abbreviation = L["FOURTH_NUMBER_CAP_NO_SPACE"], significandDivisor = 100000000000, fractionDivisor = 10 }, { breakpoint = 1000000000000, abbreviation = L["FOURTH_NUMBER_CAP_NO_SPACE"], significandDivisor = 100000000000, fractionDivisor = 10 },
{ breakpoint = 10000000000, abbreviation = L["THIRD_NUMBER_CAP_NO_SPACE"], significandDivisor = 1000000000, fractionDivisor = 1 }, { breakpoint = 10000000000, abbreviation = L["THIRD_NUMBER_CAP_NO_SPACE"], significandDivisor = 1000000000, fractionDivisor = 1 },
{ breakpoint = 1000000000, abbreviation = L["THIRD_NUMBER_CAP_NO_SPACE"], significandDivisor = 100000000, fractionDivisor = 10 }, { breakpoint = 1000000000, abbreviation = L["THIRD_NUMBER_CAP_NO_SPACE"], significandDivisor = 100000000, fractionDivisor = 10 },
{ breakpoint = 10000000, abbreviation = L["SECOND_NUMBER_CAP_NO_SPACE"], significandDivisor = 1000000, fractionDivisor = 1 }, { breakpoint = 10000000, abbreviation = L["SECOND_NUMBER_CAP_NO_SPACE"], significandDivisor = 1000000, fractionDivisor = 1 },
{ breakpoint = 1000000, abbreviation = L["SECOND_NUMBER_CAP_NO_SPACE"], significandDivisor = 100000, fractionDivisor = 10 }, { breakpoint = 1000000, abbreviation = L["SECOND_NUMBER_CAP_NO_SPACE"], significandDivisor = 100000, fractionDivisor = 10 },
{ breakpoint = 10000, abbreviation = L["FIRST_NUMBER_CAP_NO_SPACE"], significandDivisor = 1000, fractionDivisor = 1 }, { breakpoint = 10000, abbreviation = L["FIRST_NUMBER_CAP_NO_SPACE"], significandDivisor = 1000, fractionDivisor = 1 },
{ breakpoint = 1000, abbreviation = L["FIRST_NUMBER_CAP_NO_SPACE"], significandDivisor = 100, fractionDivisor = 10 }, { breakpoint = 1000, abbreviation = L["FIRST_NUMBER_CAP_NO_SPACE"], significandDivisor = 100, fractionDivisor = 10 },
} }
function AbbreviateNumbers(value) function AbbreviateNumbers(value)
for i, data in ipairs(NUMBER_ABBREVIATION_DATA) do for i, data in ipairs(NUMBER_ABBREVIATION_DATA) do
if value >= data.breakpoint then if value >= data.breakpoint then
local finalValue = math.floor(value / data.significandDivisor) / data.fractionDivisor; local finalValue = math.floor(value / data.significandDivisor) / data.fractionDivisor;
return finalValue .. data.abbreviation; return finalValue .. data.abbreviation;
end end
end end
return tostring(value); return tostring(value);
end end