Skip to content

Commit

Permalink
bug fixes, formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
massivefermion authored and PgBiel committed Aug 1, 2024
1 parent 5ed605e commit 2d1e2ed
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 401 deletions.
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "birl"
version = "1.7.0"
version = "1.7.1"
description = "Glistix fork of birl, a Date / Time handling library"
gleam = ">= 0.32.0"
internal_modules = ["birl/zones"]
Expand Down
54 changes: 20 additions & 34 deletions src/birl.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ pub fn parse(value: String) -> Result(Time, Nil) {
Ok(#(time_string, Ok(0)))
}
[time_string, milli_seconds_string], [_]
| [_], [time_string, milli_seconds_string] -> {
| [_], [time_string, milli_seconds_string]
-> {
Ok(#(
time_string,
milli_seconds_string
Expand Down Expand Up @@ -445,7 +446,8 @@ pub fn parse_time_of_day(value: String) -> Result(#(TimeOfDay, String), Nil) {
Ok(#(time_string, Ok(0)))
}
[time_string, milli_seconds_string], [_]
| [_], [time_string, milli_seconds_string] -> {
| [_], [time_string, milli_seconds_string]
-> {
Ok(#(
time_string,
milli_seconds_string
Expand Down Expand Up @@ -493,7 +495,8 @@ pub fn parse_naive_time_of_day(
Ok(#(time_string, Ok(0)))
}
[time_string, milli_seconds_string], [_]
| [_], [time_string, milli_seconds_string] -> {
| [_], [time_string, milli_seconds_string]
-> {
Ok(#(
time_string,
milli_seconds_string
Expand Down Expand Up @@ -608,7 +611,8 @@ pub fn from_naive(value: String) -> Result(Time, Nil) {
[_], [_] -> Ok(#(time_string, Ok(0)))

[time_string, milli_seconds_string], [_]
| [_], [time_string, milli_seconds_string] ->
| [_], [time_string, milli_seconds_string]
->
Ok(#(
time_string,
milli_seconds_string
Expand Down Expand Up @@ -913,12 +917,8 @@ pub fn difference(a: Time, b: Time) -> duration.Duration {
}

const string_to_units = [
#("year", duration.Year),
#("month", duration.Month),
#("week", duration.Week),
#("day", duration.Day),
#("hour", duration.Hour),
#("minute", duration.Minute),
#("year", duration.Year), #("month", duration.Month), #("week", duration.Week),
#("day", duration.Day), #("hour", duration.Hour), #("minute", duration.Minute),
#("second", duration.Second),
]

Expand Down Expand Up @@ -965,12 +965,8 @@ pub fn parse_relative(origin: Time, legible_difference: String) {
}

const units_to_string = [
#(duration.Year, "year"),
#(duration.Month, "month"),
#(duration.Week, "week"),
#(duration.Day, "day"),
#(duration.Hour, "hour"),
#(duration.Minute, "minute"),
#(duration.Year, "year"), #(duration.Month, "month"), #(duration.Week, "week"),
#(duration.Day, "day"), #(duration.Hour, "hour"), #(duration.Minute, "minute"),
#(duration.Second, "second"),
]

Expand Down Expand Up @@ -1630,28 +1626,18 @@ fn month_from_int(month: Int) -> Result(Month, Nil) {
}

const weekday_strings = [
#(Mon, #("Monday", "Mon")),
#(Tue, #("Tuesday", "Tue")),
#(Wed, #("Wednesday", "Wed")),
#(Thu, #("Thursday", "Thu")),
#(Fri, #("Friday", "Fri")),
#(Sat, #("Saturday", "Sat")),
#(Mon, #("Monday", "Mon")), #(Tue, #("Tuesday", "Tue")),
#(Wed, #("Wednesday", "Wed")), #(Thu, #("Thursday", "Thu")),
#(Fri, #("Friday", "Fri")), #(Sat, #("Saturday", "Sat")),
#(Sun, #("Sunday", "Sun")),
]

const month_strings = [
#(Jan, #("January", "Jan")),
#(Feb, #("February", "Feb")),
#(Mar, #("March", "Mar")),
#(Apr, #("April", "Apr")),
#(May, #("May", "May")),
#(Jun, #("June", "Jun")),
#(Jul, #("July", "Jul")),
#(Aug, #("August", "Aug")),
#(Sep, #("September", "Sep")),
#(Oct, #("October", "Oct")),
#(Nov, #("November", "Nov")),
#(Dec, #("December", "Dec")),
#(Jan, #("January", "Jan")), #(Feb, #("February", "Feb")),
#(Mar, #("March", "Mar")), #(Apr, #("April", "Apr")), #(May, #("May", "May")),
#(Jun, #("June", "Jun")), #(Jul, #("July", "Jul")), #(Aug, #("August", "Aug")),
#(Sep, #("September", "Sep")), #(Oct, #("October", "Oct")),
#(Nov, #("November", "Nov")), #(Dec, #("December", "Dec")),
]

@external(erlang, "birl_ffi", "now")
Expand Down
21 changes: 5 additions & 16 deletions src/birl/duration.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,8 @@ const accurate_month = 2_629_746_000_000
const accurate_year = 31_556_952_000_000

const unit_values = [
#(Year, year),
#(Month, month),
#(Week, week),
#(Day, day),
#(Hour, hour),
#(Minute, minute),
#(Second, second),
#(MilliSecond, milli_second),
#(Year, year), #(Month, month), #(Week, week), #(Day, day), #(Hour, hour),
#(Minute, minute), #(Second, second), #(MilliSecond, milli_second),
#(MicroSecond, 1),
]

Expand Down Expand Up @@ -292,14 +286,9 @@ const milli_second_units = [
]

const units = [
#(Year, year_units),
#(Month, month_units),
#(Week, week_units),
#(Day, day_units),
#(Hour, hour_units),
#(Minute, minute_units),
#(Second, second_units),
#(MilliSecond, milli_second_units),
#(Year, year_units), #(Month, month_units), #(Week, week_units),
#(Day, day_units), #(Hour, hour_units), #(Minute, minute_units),
#(Second, second_units), #(MilliSecond, milli_second_units),
]

/// you can use this function to create a new duration using expressions like:
Expand Down
Loading

0 comments on commit 2d1e2ed

Please sign in to comment.