Skip to content

Commit

Permalink
fix: mark failable std date functions as failable & clippy issue (#382
Browse files Browse the repository at this point in the history
)

* fix: mark failable std `date` functions as failable

* fix: clippy issue
  • Loading branch information
MuhamedMagdi committed Jul 31, 2024
1 parent 71224ec commit 042ca2a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
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

0 comments on commit 042ca2a

Please sign in to comment.