Skip to content

Commit

Permalink
use ~c"" for charlists
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmcconnell authored and bitwalker committed Sep 25, 2024
1 parent c45b9a7 commit 01ad66b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions lib/parse/duration/parsers/iso8601.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -127,7 +127,7 @@ defmodule Timex.Parse.Duration.Parsers.ISO8601Parser do
defp parse_component(<<c::utf8>>, _acc) when c in @numeric,
do: {:error, "unexpected end of input at #{<<c::utf8>>}"}

defp parse_component(<<c::utf8>>, {type, acc}) when c in 'WYMDHS' do
defp parse_component(<<c::utf8>>, {type, acc}) when c in ~c"WYMDHS" do
case cast_number(type, acc) do
{n, _} -> {c, n, <<>>}
:error -> {:error, "invalid number `#{acc}`"}
Expand All @@ -146,7 +146,7 @@ defmodule Timex.Parse.Duration.Parsers.ISO8601Parser do
parse_component(rest, {:float, <<acc::binary, c::utf8>>})
end

defp parse_component(<<c::utf8, rest::binary>>, {type, acc}) when c in 'WYMDHS' do
defp parse_component(<<c::utf8, rest::binary>>, {type, acc}) when c in ~c"WYMDHS" do
case cast_number(type, acc) do
{n, _} -> {c, n, rest}
:error -> {:error, "invalid number `#{acc}`"}
Expand Down
12 changes: 6 additions & 6 deletions lib/timezone/local.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 01ad66b

Please sign in to comment.