From 01ad66b408325893e8bc4f419b94ace6ad1f77d0 Mon Sep 17 00:00:00 2001 From: Simon McConnell <22566656+simonmcconnell@users.noreply.github.com> Date: Thu, 13 Jun 2024 13:05:01 +0800 Subject: [PATCH] use ~c"" for charlists --- CHANGELOG.md | 1 + lib/parse/duration/parsers/iso8601.ex | 6 +++--- lib/timezone/local.ex | 12 ++++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b17b05c5..fdd114bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Fixed compilation warning from gettext - Added `cycled` option for `Timex.between?/4` to support time-range checks that pass through midnight - Add Croatian translation +- Changed charlists from the deprecated `''` to `~c""` ### Fixed diff --git a/lib/parse/duration/parsers/iso8601.ex b/lib/parse/duration/parsers/iso8601.ex index 0e363483..b59a3646 100644 --- a/lib/parse/duration/parsers/iso8601.ex +++ b/lib/parse/duration/parsers/iso8601.ex @@ -4,7 +4,7 @@ defmodule Timex.Parse.Duration.Parsers.ISO8601Parser do """ use Timex.Parse.Duration.Parser - @numeric '.0123456789' + @numeric ~c".0123456789" @doc """ Parses an ISO-8601 formatted duration string into a Duration struct. @@ -127,7 +127,7 @@ defmodule Timex.Parse.Duration.Parsers.ISO8601Parser do defp parse_component(<>, _acc) when c in @numeric, do: {:error, "unexpected end of input at #{<>}"} - defp parse_component(<>, {type, acc}) when c in 'WYMDHS' do + defp parse_component(<>, {type, acc}) when c in ~c"WYMDHS" do case cast_number(type, acc) do {n, _} -> {c, n, <<>>} :error -> {:error, "invalid number `#{acc}`"} @@ -146,7 +146,7 @@ defmodule Timex.Parse.Duration.Parsers.ISO8601Parser do parse_component(rest, {:float, <>}) end - defp parse_component(<>, {type, acc}) when c in 'WYMDHS' do + defp parse_component(<>, {type, acc}) when c in ~c"WYMDHS" do case cast_number(type, acc) do {n, _} -> {c, n, rest} :error -> {:error, "invalid number `#{acc}`"} diff --git a/lib/timezone/local.ex b/lib/timezone/local.ex index b644ec5c..89bc2246 100644 --- a/lib/timezone/local.ex +++ b/lib/timezone/local.ex @@ -150,16 +150,16 @@ defmodule Timex.Timezone.Local do end # Get the locally configured timezone on Windows systems - @local_tz_key 'SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation' - @sys_tz_key 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones' - @tz_key_name 'TimeZoneKeyName' + @local_tz_key ~c"SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation" + @sys_tz_key ~c"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones" + @tz_key_name ~c"TimeZoneKeyName" # We ignore the reference date here, since there is no way to lookup # transition times for historical/future dates defp localtz(:win) do # Windows has many of its own unique time zone names, which can # also be translated to the OS's language. {:ok, handle} = :win32reg.open([:read]) - :ok = :win32reg.change_key(handle, '\\local_machine\\#{@local_tz_key}') + :ok = :win32reg.change_key(handle, ~c"\\local_machine\\#{@local_tz_key}") {:ok, values} = :win32reg.values(handle) if List.keymember?(values, @tz_key_name, 0) do @@ -177,7 +177,7 @@ defmodule Timex.Timezone.Local do else # Windows 2000 or XP # This is the localized name: - localized = List.keyfind(values, 'StandardName', 0) + localized = List.keyfind(values, ~c"StandardName", 0) # Open the list of timezones to look up the real name: :ok = :win32reg.change_key(handle, @sys_tz_key) {:ok, subkeys} = :win32reg.sub_keys(handle) @@ -187,7 +187,7 @@ defmodule Timex.Timezone.Local do :ok = :win32reg.change_key(handle, subkey) {:ok, values} = :win32reg.values(handle) - case List.keyfind(values, 'Std', 0) do + case List.keyfind(values, ~c"Std", 0) do {_, zone} when zone == localized -> zone _ -> nil end