diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious/helpers/utils.cr | 18 | ||||
| -rw-r--r-- | src/invidious/user/preferences.cr | 6 |
2 files changed, 21 insertions, 3 deletions
diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index 22575c57..53f64f4e 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -53,6 +53,24 @@ def recode_length_seconds(time : Int32) : String end end +def decode_interval(string : String) : Time::Span + rawMinutes = string.try &.to_i32? + + if !rawMinutes + hours = /(?<hours>\d+)h/.match(string).try &.["hours"].try &.to_i32 + hours ||= 0 + + minutes = /(?<minutes>\d+)m(?!s)/.match(string).try &.["minutes"].try &.to_i32 + minutes ||= 0 + + time = Time::Span.new(hours: hours, minutes: minutes) + else + time = Time::Span.new(minutes: rawMinutes) + end + + return time +end + def decode_time(string) time = string.try &.to_f? diff --git a/src/invidious/user/preferences.cr b/src/invidious/user/preferences.cr index c01bdd82..9eeed53f 100644 --- a/src/invidious/user/preferences.cr +++ b/src/invidious/user/preferences.cr @@ -259,15 +259,15 @@ struct Preferences module TimeSpanConverter def self.to_yaml(value : Time::Span, yaml : YAML::Nodes::Builder) - return yaml.scalar recode_length_seconds(value.total_seconds.to_i32) + return yaml.scalar value.total_minutes.to_i32 end def self.from_yaml(ctx : YAML::ParseContext, node : YAML::Nodes::Node) : Time::Span if node.is_a?(YAML::Nodes::Scalar) - return decode_time_span(node.value) + return decode_interval(node.value) else node.raise "Expected scalar, not #{node.class}" end end end -end
\ No newline at end of file +end |
