Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mark failable std date functions as failable & clippy issue #382

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/modules/function/ret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl SyntaxModule<ParserMetadata> for Return {
types @ (Some(Type::Failable(_)), Type::Failable(_)) => types,
(Some(Type::Failable(ret_type)), expr_type) => (Some(ret_type.as_ref()), expr_type),
(Some(ret_type), Type::Failable(expr_type)) => (Some(ret_type), expr_type.as_ref()),
types @ _ => types
types => types
};
match ret_type {
Some(ret_type) => {
Expand Down
6 changes: 3 additions & 3 deletions src/std/date.ab
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
/// + pad with zeros, and put '+' before future years with >4 digits
/// ^ use upper case if possible
/// # use opposite case if possible
pub fun date_posix(format: Text = "", date: Text = "", utc: Bool = false): Text {
pub fun date_posix(format: Text = "", date: Text = "", utc: Bool = false): Text? {
if format == "": format = "%FT%T%Z"
if date == "": date = unsafe $date +"%FT%T%Z"$
if (utc) {
Expand Down Expand Up @@ -87,7 +87,7 @@ pub fun now(): Num {
/// hours
/// minutes
/// seconds
pub fun date_add(add:Text, date:Text = "", utc: Bool = false): Text {
pub fun date_add(add:Text, date:Text = "", utc: Bool = false): Text? {
if date == "": date = unsafe $date +"%FT%T%Z"$
return date_posix("", "{date_posix("%F", date, utc)?} {add} {date_posix("%T", date, utc)?}", utc)?
}
Expand All @@ -99,7 +99,7 @@ pub fun date_add(add:Text, date:Text = "", utc: Bool = false): Text {
// Return -1 if date_b is after date_a
// If date_b is not provided, current date will be used
#[allow_absurd_cast]
pub fun date_compare(date_a: Text, date_b: Text = "", utc: Bool = false): Num {
pub fun date_compare(date_a: Text, date_b: Text = "", utc: Bool = false): Num? {
if date_b == "": date_b = unsafe date_posix("", "", utc)
let timestamp_a = date_posix("%s", date_a, utc)? as Num
let timestamp_b = date_posix("%s", date_b, utc)? as Num
Expand Down