# A text representation of a shorthand timespan function shorthandTimespanText(cand: text) :: text: if {_cand} is "forever": return "forever" set {_spans::*} to regex split {_cand} with pattern "\d+" remove all "" from {_spans::*} set {_nums::*} to regex split {_cand} with pattern "[a-zA-Z]+" remove all "" from {_nums::*} if size of {_nums::*} = size of {_spans::*}: set {_declaredletters::*} to "s", "m", "h", "d", "w", "mo", and "y" set {_declaredtrans::*} to "seconds", "minutes", "hours", "days", "weeks", "months", and "years" set {_iter} to 1 set {_cap} to size of {_spans::*} while {_iter} <= {_cap}: set {_cnum} to the first element of {_nums::*} set {_cspan} to the first element of {_spans::*} remove the first element of {_nums::*} from {_nums::*} remove the first element of {_spans::*} from {_spans::*} set {_found} to -1 loop {_declaredletters::*}: if loop-value is {_cspan}: set {_found} to (loop-index parsed as number) exit 1 loop set {_parsednum} to {_cnum} parsed as number if {_priority::%{_found}%} is not set: set {_priority::%{_found}%} to true set {_priority::%{_found}%::amt} to 0 add {_parsednum} to {_priority::%{_found}%::amt} # Unrecognized short span sequence if {_found} = -1: return {_unset} add 1 to {_iter} set {_declaredsize} to size of {_declaredtrans::*} set {_builder} to "" while {_declaredsize} >= 1: if {_priority::%{_declaredsize}%} is set: set {_amt} to {_priority::%{_declaredsize}%::amt} set {_len} to {_declaredtrans::%{_declaredsize}%} # Remove the 's' if not plural if {_amt} = 1: set {_len} to the first ((length of {_len}) - 1) characters of {_len} set {_builder} to "%{_builder}%%{_amt}% %{_len}%, " remove 1 from {_declaredsize} # Remove last two chars, ', ' set {_builder} to the first ((length of {_builder}) - 2) characters of {_builder} return {_builder} else: return {_unset} # A timespan translation of a shorthand timespan function shorthandTimespan(cand: text) :: timespan: if {_cand} is "forever": return 40150 days set {_spans::*} to regex split {_cand} with pattern "\d+" remove all "" from {_spans::*} set {_nums::*} to regex split {_cand} with pattern "[a-zA-Z]+" remove all "" from {_nums::*} if size of {_nums::*} = size of {_spans::*}: set {_declaredletters::*} to "s", "m", "h", "d", "w", "mo", and "y" set {_declaredtrans::*} to "seconds", "minutes", "hours", "days", "weeks", "months", and "years" set {_iter} to 1 set {_cap} to size of {_spans::*} set {_builder} to "" while {_iter} <= {_cap}: set {_cnum} to the first element of {_nums::*} set {_cspan} to the first element of {_spans::*} remove the first element of {_nums::*} from {_nums::*} remove the first element of {_spans::*} from {_spans::*} set {_found} to -1 loop {_declaredletters::*}: if loop-value is {_cspan}: set {_found} to (loop-index parsed as number) exit 1 loop # Unrecognized short span sequence if {_found} = -1: return {_unset} else: set {_parsednum} to {_cnum} parsed as number set {_translated} to {_declaredtrans::%{_found}%} # Skript does not support these lengths in its timespan expression, convert to days as a workaround set {_unsupported::*} to "weeks", "months", and "years" if {_unsupported::*} contains {_translated}: set {_factor} to 1 if {_translated} is "weeks": set {_factor} to 7 else if {_translated} is "months": set {_factor} to 31 else if {_translated} is "years": set {_factor} to 365 set {_parsednum} to {_parsednum} * {_factor} set {_translated} to "days" set {_builder} to "%{_builder}%%{_parsednum}% %{_translated}% " add 1 to {_iter} # Remove any trailing whitespace set {_builder} to regex replace "[ \t]+$" with "" in {_builder} return {_builder} parsed as timespan else: return {_unset}