Skip to content

Commit

Permalink
Merge pull request #44 from imclerran/snake_case
Browse files Browse the repository at this point in the history
Upgrade to PNC and snake_case
  • Loading branch information
imclerran authored Jan 14, 2025
2 parents e91ef22 + aa6ff81 commit 66cd426
Show file tree
Hide file tree
Showing 12 changed files with 904 additions and 875 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
id: try_fetching_testing_release
continue-on-error: true
run: |
curl -fOL https://github.com/roc-lang/roc/releases/download/nightly/roc_nightly-linuxTESTING_x86_64-latest.tar.gz
curl -fOL https://github.com/roc-lang/roc/releases/download/nightly/roc_nightly-linux_x86_64-TESTING.tar.gz
- name: There are no TESTING releases, checking regular releases instead
if: steps.try_fetching_testing_release.outcome == 'failure'
Expand Down
52 changes: 27 additions & 25 deletions examples/iso-to-datetime.roc
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
app [main] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.17.0/lZFLstMUCUvd5bjnnpYromZJXkQUrdhbva4xdBInicE.tar.br",
app [main!] {
pf: platform "../../basic-cli/platform/main.roc",
# pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.17.0/lZFLstMUCUvd5bjnnpYromZJXkQUrdhbva4xdBInicE.tar.br",
dt: "../package/main.roc",
}

import pf.Http
import pf.Stdout
import dt.DateTime

main =
response = Http.send! (format_request "America/Chicago")
main! = \_ ->
response = Http.send!(format_request("America/Chicago"))

response_body =
when response |> Http.handleStringResponse is
Err err -> crash (Http.errorToString err)
Ok body -> body
when response is
Ok { status, body } if status == 200 -> Str.from_utf8(body)?
_ -> crash("Error getting response body")

iso_str = get_iso_string response_body
iso_str = get_iso_string(response_body)

dt_now =
when DateTime.from_iso_str iso_str is
Ok date_time -> date_time
Err _ -> crash "Parsing Error"
when DateTime.from_iso_str(iso_str) is
Ok(date_time) -> date_time
Err(_) -> crash("Parsing Error")

time_str = "$(Num.toStr dt_now.time.hour):$(Num.toStr dt_now.time.minute):$(Num.toStr dt_now.time.second)"
date_str = "$(Num.toStr dt_now.date.year)-$(Num.toStr dt_now.date.month)-$(Num.toStr dt_now.date.day_of_month)"
Stdout.line! "The current Zulut date is: $(date_str)"
Stdout.line! "The current Zulu time is: $(time_str)"
time_str = "${Num.to_str(dt_now.time.hour)}:${Num.to_str(dt_now.time.minute)}:${Num.to_str(dt_now.time.second)}"
date_str = "${Num.to_str(dt_now.date.year)}-${Num.to_str(dt_now.date.month)}-${Num.to_str(dt_now.date.day_of_month)}"
try Stdout.line!("The current Zulu date is: ${date_str}")
try Stdout.line!("The current Zulu time is: ${time_str}")
Ok {}
format_request = \timezone -> {
method: Get,
method: GET,
headers: [],
url: "http://worldtimeapi.org/api/timezone/$(timezone).txt",
mimeType: "",
uri: "http://worldtimeapi.org/api/timezone/${timezone}.txt",
body: [],
timeout: TimeoutMilliseconds 5000,
timeout_ms: TimeoutMilliseconds(5000),
}
get_iso_string = \body ->
when Str.splitOn body "\n" |> List.get 3 is
Ok line ->
when Str.splitFirst line ":" is
Ok line_parts -> line_parts.after |> Str.trim
Err _ -> crash "Error splitting line at delimiter"
when Str.split_on(body, "\n") |> List.get(3) is
Ok(line) ->
when Str.split_first(line, ":") is
Ok(line_parts) -> line_parts.after |> Str.trim
Err(_) -> crash("Error splitting line at delimiter")
Err _ -> crash "Error getting output line"
Err(_) -> crash("Error getting output line")
13 changes: 7 additions & 6 deletions examples/utc-to-datetime.roc
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
app [main] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.17.0/lZFLstMUCUvd5bjnnpYromZJXkQUrdhbva4xdBInicE.tar.br",
app [main!] {
pf: platform "../../basic-cli/platform/main.roc",
# pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.17.0/lZFLstMUCUvd5bjnnpYromZJXkQUrdhbva4xdBInicE.tar.br",
dt: "../package/main.roc",
}

import pf.Stdout
import pf.Utc
import dt.DateTime

main =
utc_now = Utc.now! {}
main! = \_ ->
utc_now = Utc.now!({})
now_str =
utc_now
|> Utc.toNanosSinceEpoch
|> Utc.to_nanos_since_epoch
|> DateTime.from_nanos_since_epoch
|> DateTime.to_iso_str
Stdout.line! "Hello, World! The current Zulu time is: $(now_str)"
Stdout.line!("Hello, World! The current Zulu time is: ${now_str}")
4 changes: 2 additions & 2 deletions package/Const.roc
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ days_per_leap_year = 366
days_per_week = 7
weeks_per_year = 52

month_days : { month : Int *, is_leap ? Bool } -> U64
month_days = \{ month, is_leap ? Bool.false } ->
month_days : { month : Int *, is_leap ?? Bool } -> U64
month_days = \{ month, is_leap ?? Bool.false } ->
when month is
1 | 3 | 5 | 7 | 8 | 10 | 12 -> 31
4 | 6 | 9 | 11 -> 30
Expand Down
10 changes: 5 additions & 5 deletions package/ContextualDuration.roc
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ module [
ContextualDuration : { years : I64, months : I8, days : I16, hours : I8, minutes : I8, seconds : I8, nanoseconds : I32 }

from_ymd : Int *, Int *, Int * -> ContextualDuration
from_ymd = \y, m, d -> { years: Num.toI64 y, months: Num.toI8 m, days: Num.toI16 d, hours: 0, minutes: 0, seconds: 0, nanoseconds: 0 }
from_ymd = \y, m, d -> { years: Num.to_i64(y), months: Num.to_i8(m), days: Num.to_i16(d), hours: 0, minutes: 0, seconds: 0, nanoseconds: 0 }

from_hms : Int *, Int *, Int * -> ContextualDuration
from_hms = \h, m, s -> { years: 0, months: 0, days: 0, hours: Num.toI8 h, minutes: Num.toI8 m, seconds: Num.toI8 s, nanoseconds: 0 }
from_hms = \h, m, s -> { years: 0, months: 0, days: 0, hours: Num.to_i8(h), minutes: Num.to_i8(m), seconds: Num.to_i8(s), nanoseconds: 0 }

from_hmsn : Int *, Int *, Int *, Int * -> ContextualDuration
from_hmsn = \h, m, s, n -> { years: 0, months: 0, days: 0, hours: Num.toI8 h, minutes: Num.toI8 m, seconds: Num.toI8 s, nanoseconds: Num.toI32 n }
from_hmsn = \h, m, s, n -> { years: 0, months: 0, days: 0, hours: Num.to_i8(h), minutes: Num.to_i8(m), seconds: Num.to_i8(s), nanoseconds: Num.to_i32(n) }

from_ymd_hms : Int *, Int *, Int *, Int *, Int *, Int * -> ContextualDuration
from_ymd_hms = \y, m, d, h, mi, s -> { years: Num.toI64 y, months: Num.toI8 m, days: Num.toI16 d, hours: Num.toI8 h, minutes: Num.toI8 mi, seconds: Num.toI8 s, nanoseconds: 0 }
from_ymd_hms = \y, m, d, h, mi, s -> { years: Num.to_i64(y), months: Num.to_i8(m), days: Num.to_i16(d), hours: Num.to_i8(h), minutes: Num.to_i8(mi), seconds: Num.to_i8(s), nanoseconds: 0 }

from_ymd_hmsn : Int *, Int *, Int *, Int *, Int *, Int *, Int * -> ContextualDuration
from_ymd_hmsn = \y, m, d, h, mi, s, n -> { years: Num.toI64 y, months: Num.toI8 m, days: Num.toI16 d, hours: Num.toI8 h, minutes: Num.toI8 mi, seconds: Num.toI8 s, nanoseconds: Num.toI32 n }
from_ymd_hmsn = \y, m, d, h, mi, s, n -> { years: Num.to_i64(y), months: Num.to_i8(m), days: Num.to_i16(d), hours: Num.to_i8(h), minutes: Num.to_i8(mi), seconds: Num.to_i8(s), nanoseconds: Num.to_i32(n) }
Loading

0 comments on commit 66cd426

Please sign in to comment.