From 946eaea5f80e7d0e32bac0941dd518e950b953aa Mon Sep 17 00:00:00 2001 From: Richard Viney Date: Tue, 19 Nov 2024 13:36:15 +1300 Subject: [PATCH] Fix deprecation warnings with latest stdlib version --- .github/workflows/test.yml | 2 +- gleam.toml | 6 +-- manifest.toml | 10 ++-- src/birl.gleam | 105 ++++++++++++++++++------------------- 4 files changed, 61 insertions(+), 62 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 95eefa6..6f01bbf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: - uses: erlef/setup-beam@v1 with: otp-version: '26' - gleam-version: '1.2' + gleam-version: '1.6' rebar3-version: '3' - run: gleam test - run: gleam format --check src test diff --git a/gleam.toml b/gleam.toml index 3c95929..036b932 100644 --- a/gleam.toml +++ b/gleam.toml @@ -9,8 +9,8 @@ repository = { type = "github", user = "massivefermion", repo = "birl" } links = [{ title = "Gleam", href = "https://gleam.run" }] [dependencies] -ranger = "~> 1.2" -gleam_stdlib = "~> 0.38 or ~> 1.0" +ranger = ">= 1.2.0 and < 2.0.0" +gleam_stdlib = ">= 0.43.0 and < 2.0.0" [dev-dependencies] -gleeunit = "~> 1.1" +gleeunit = ">= 1.2.0 and < 2.0.0" diff --git a/manifest.toml b/manifest.toml index 1fd33c7..18fa7cd 100644 --- a/manifest.toml +++ b/manifest.toml @@ -2,12 +2,12 @@ # You typically do not need to edit this file packages = [ - { name = "gleam_stdlib", version = "0.38.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "663CF11861179AF415A625307447775C09404E752FF99A24E2057C835319F1BE" }, - { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, + { name = "gleam_stdlib", version = "0.43.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "69EF22E78FDCA9097CBE7DF91C05B2A8B5436826D9F66680D879182C0860A747" }, + { name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" }, { name = "ranger", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "ranger", source = "hex", outer_checksum = "1566C272B1D141B3BBA38B25CB761EF56E312E79EC0E2DFD4D3C19FB0CC1F98C" }, ] [requirements] -gleam_stdlib = { version = "~> 0.38 or ~> 1.0" } -gleeunit = { version = "~> 1.1" } -ranger = { version = "~> 1.2" } +gleam_stdlib = { version = ">= 0.43.0 and < 2.0.0" } +gleeunit = { version = ">= 1.2.0 and < 2.0.0" } +ranger = { version = ">= 1.2.0 and < 2.0.0" } diff --git a/src/birl.gleam b/src/birl.gleam index 5f37260..e4e830e 100644 --- a/src/birl.gleam +++ b/src/birl.gleam @@ -131,13 +131,13 @@ pub fn to_date_string(value: Time) -> String { <> { month |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> "-" <> { day |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> offset } @@ -151,13 +151,13 @@ pub fn to_naive_date_string(value: Time) -> String { <> { month |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> "-" <> { day |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } } @@ -168,25 +168,25 @@ pub fn to_time_string(value: Time) -> String { { hour |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> ":" <> { minute |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> ":" <> { second |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> "." <> { milli_second |> int.to_string - |> string.pad_left(3, "0") + |> string.pad_start(3, "0") } <> offset } @@ -198,25 +198,25 @@ pub fn to_naive_time_string(value: Time) -> String { { hour |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> ":" <> { minute |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> ":" <> { second |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> "." <> { milli_second |> int.to_string - |> string.pad_left(3, "0") + |> string.pad_start(3, "0") } } @@ -229,37 +229,37 @@ pub fn to_iso8601(value: Time) -> String { <> { month |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> "-" <> { day |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> "T" <> { hour |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> ":" <> { minute |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> ":" <> { second |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> "." <> { milli_second |> int.to_string - |> string.pad_left(3, "0") + |> string.pad_start(3, "0") } <> offset } @@ -316,7 +316,7 @@ pub fn parse(value: String) -> Result(Time, Nil) { || string.ends_with(offsetted_time_string, "z") { True -> - Ok(#(day_string, string.drop_right(offsetted_time_string, 1), "+00:00")) + Ok(#(day_string, string.drop_end(offsetted_time_string, 1), "+00:00")) False -> case regex.scan(offset_pattern, offsetted_time_string) { [regex.Match(_, [option.Some(time_string), option.Some(offset_string)])] -> @@ -349,7 +349,7 @@ pub fn parse(value: String) -> Result(Time, Nil) { time_string, milli_seconds_string |> string.slice(0, 3) - |> string.pad_right(3, "0") + |> string.pad_end(3, "0") |> int.parse, )) } @@ -401,15 +401,14 @@ pub fn parse_time_of_day(value: String) -> Result(#(TimeOfDay, String), Nil) { string.starts_with(value, "T"), string.starts_with(value, "t") { - True, _ | _, True -> string.drop_left(value, 1) + True, _ | _, True -> string.drop_start(value, 1) _, _ -> value } use #(time_string, offset_string) <- result.then(case - string.ends_with(time_string, "Z") - || string.ends_with(time_string, "z") + string.ends_with(time_string, "Z") || string.ends_with(time_string, "z") { - True -> Ok(#(string.drop_right(value, 1), "+00:00")) + True -> Ok(#(string.drop_end(value, 1), "+00:00")) False -> case regex.scan(offset_pattern, value) { [regex.Match(_, [option.Some(time_string), option.Some(offset_string)])] -> @@ -434,7 +433,7 @@ pub fn parse_time_of_day(value: String) -> Result(#(TimeOfDay, String), Nil) { time_string, milli_seconds_string |> string.slice(0, 3) - |> string.pad_right(3, "0") + |> string.pad_end(3, "0") |> int.parse, )) } @@ -463,7 +462,7 @@ pub fn parse_naive_time_of_day( string.starts_with(value, "T"), string.starts_with(value, "t") { - True, _ | _, True -> string.drop_left(value, 1) + True, _ | _, True -> string.drop_start(value, 1) _, _ -> value } @@ -483,7 +482,7 @@ pub fn parse_naive_time_of_day( time_string, milli_seconds_string |> string.slice(0, 3) - |> string.pad_right(3, "0") + |> string.pad_end(3, "0") |> int.parse, )) } @@ -505,20 +504,20 @@ pub fn time_of_day_to_string(value: TimeOfDay) -> String { int.to_string(value.hour) <> ":" <> int.to_string(value.minute) - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") <> ":" <> int.to_string(value.second) - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") <> "." <> int.to_string(value.milli_second) - |> string.pad_left(3, "0") + |> string.pad_start(3, "0") } pub fn time_of_day_to_short_string(value: TimeOfDay) -> String { int.to_string(value.hour) <> ":" <> int.to_string(value.minute) - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } /// the naive format is the same as ISO8601 except that it does not contain the offset @@ -531,37 +530,37 @@ pub fn to_naive(value: Time) -> String { <> { month |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> "-" <> { day |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> "T" <> { hour |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> ":" <> { minute |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> ":" <> { second |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> "." <> { milli_second |> int.to_string - |> string.pad_left(3, "0") + |> string.pad_start(3, "0") } } @@ -599,7 +598,7 @@ pub fn from_naive(value: String) -> Result(Time, Nil) { time_string, milli_seconds_string |> string.slice(0, 3) - |> string.pad_right(3, "0") + |> string.pad_end(3, "0") |> int.parse, )) @@ -637,7 +636,7 @@ pub fn to_http(value: Time) -> String { <> { day |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> " " <> short_month @@ -647,19 +646,19 @@ pub fn to_http(value: Time) -> String { <> { hour |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> ":" <> { minute |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> ":" <> { second |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> " GMT" } @@ -680,7 +679,7 @@ pub fn to_http_with_offset(value: Time) -> String { <> { day |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> " " <> short_month @@ -690,19 +689,19 @@ pub fn to_http_with_offset(value: Time) -> String { <> { hour |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> ":" <> { minute |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> ":" <> { second |> int.to_string - |> string.pad_left(2, "0") + |> string.pad_start(2, "0") } <> " " <> offset @@ -919,7 +918,7 @@ pub fn parse_relative(origin: Time, legible_difference: String) { | [amount_string, unit, "hence"] -> { let unit = case string.ends_with(unit, "s") { False -> unit - True -> string.drop_right(unit, 1) + True -> string.drop_end(unit, 1) } use amount <- result.then(int.parse(amount_string)) @@ -934,7 +933,7 @@ pub fn parse_relative(origin: Time, legible_difference: String) { | [amount_string, unit, "in the past"] -> { let unit = case string.ends_with(unit, "s") { False -> unit - True -> string.drop_right(unit, 1) + True -> string.drop_end(unit, 1) } use amount <- result.then(int.parse(amount_string)) @@ -1387,7 +1386,7 @@ fn generate_offset(offset: Int) -> Result(String, Nil) { "+", hour |> int.to_string - |> string.pad_left(2, "0"), + |> string.pad_start(2, "0"), ]) False -> string.concat([ @@ -1395,13 +1394,13 @@ fn generate_offset(offset: Int) -> Result(String, Nil) { hour |> int.absolute_value |> int.to_string - |> string.pad_left(2, "0"), + |> string.pad_start(2, "0"), ]) }, minute |> int.absolute_value |> int.to_string - |> string.pad_left(2, "0"), + |> string.pad_start(2, "0"), ] |> string.join(":") |> Ok @@ -1414,7 +1413,7 @@ fn generate_offset(offset: Int) -> Result(String, Nil) { "+", hour |> int.to_string - |> string.pad_left(2, "0"), + |> string.pad_start(2, "0"), ]) False -> string.concat([ @@ -1422,7 +1421,7 @@ fn generate_offset(offset: Int) -> Result(String, Nil) { hour |> int.absolute_value |> int.to_string - |> string.pad_left(2, "0"), + |> string.pad_start(2, "0"), ]) }, "00",