Swap if end > start

This commit is contained in:
Hans5958 2022-05-05 15:09:56 +07:00
parent 57a254fe8e
commit 06fc5d51df

View file

@ -266,7 +266,7 @@ function parsePeriod(periodString) {
periodString = split[1] periodString = split[1]
} }
if (periodString.search('-') + 1) { if (periodString.search('-') + 1) {
let [start, end] = periodString.split('-').map(i => parseInt(i)) let [start, end] = periodString.split('-').map(i => parseInt(i)).sort()
return [start, end, variation] return [start, end, variation]
} else if (codeReference[periodString]) { } else if (codeReference[periodString]) {
variation = codeReference[periodString] variation = codeReference[periodString]
@ -287,6 +287,7 @@ function formatPeriod(start, end, variation) {
} }
else periodString = start else periodString = start
} }
if (end > start) [start, end] = [end, start]
else periodString = start + "-" + end else periodString = start + "-" + end
if (periodString && variationString) return variationsConfig[variation].code + ":" + periodString if (periodString && variationString) return variationsConfig[variation].code + ":" + periodString
if (variationString) return variationString if (variationString) return variationString