-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from imclerran/snake_case
Upgrade to PNC and snake_case
- Loading branch information
Showing
12 changed files
with
904 additions
and
875 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.