Skip to content

Commit

Permalink
fixed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
massivefermion committed May 24, 2024
1 parent 2c9f5a6 commit 3e4f1b8
Show file tree
Hide file tree
Showing 3 changed files with 390 additions and 170 deletions.
48 changes: 34 additions & 14 deletions src/birl.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ pub fn parse(value: String) -> Result(Time, Nil) {
{
[day_string, time_string], _, _
| _, [day_string, time_string], _
| _, _, [day_string, time_string] -> Ok(#(day_string, time_string))
| _, _, [day_string, time_string]
-> Ok(#(day_string, time_string))
[_], [_], [_] -> Ok(#(value, "00"))
_, _, _ -> Error(Nil)
})
Expand Down Expand Up @@ -572,7 +573,8 @@ pub fn from_naive(value: String) -> Result(Time, Nil) {
{
[day_string, time_string], _, _
| _, [day_string, time_string], _
| _, _, [day_string, time_string] -> Ok(#(day_string, time_string))
| _, _, [day_string, time_string]
-> Ok(#(day_string, time_string))
[_], [_], [_] -> Ok(#(value, "00"))
_, _, _ -> Error(Nil)
})
Expand Down Expand Up @@ -893,8 +895,12 @@ 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 @@ -941,8 +947,12 @@ 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 @@ -1584,18 +1594,28 @@ 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: 16 additions & 5 deletions src/birl/duration.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,14 @@ 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 @@ -286,9 +292,14 @@ 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 3e4f1b8

Please sign in to comment.