-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Date, Time and DateTime types
- Loading branch information
1 parent
0d93e27
commit 9b1bb36
Showing
9 changed files
with
298 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -9,3 +9,4 @@ license = "MIT" | |
|
||
[dependencies] | ||
lazy_static = "1.4.0" | ||
chrono = "0.4.28" |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
extern crate chrono; | ||
|
||
use chrono::NaiveDateTime; | ||
use chrono::TimeZone; | ||
use chrono::Utc; | ||
|
||
static CHRONO_TIME_FORMAT: &str = "%H:%M:%S"; | ||
static CHRONO_DATE_FORMAT: &str = "%Y-%m-%d"; | ||
static CHRONO_DATE_TIME_FORMAT: &str = "%Y-%m-%d %H:%M:%S"; | ||
|
||
pub fn get_unix_timestamp_ms() -> i64 { | ||
let now = Utc::now(); | ||
return now.timestamp(); | ||
} | ||
|
||
pub fn time_stamp_to_date(time_stamp: i64) -> String { | ||
let utc = NaiveDateTime::from_timestamp_opt(time_stamp, 0).unwrap(); | ||
let datetime = Utc.from_utc_datetime(&utc); | ||
let date_str = datetime.format(CHRONO_DATE_FORMAT).to_string(); | ||
return date_str; | ||
} | ||
|
||
pub fn time_stamp_to_time(time_stamp: i64) -> String { | ||
let utc = NaiveDateTime::from_timestamp_opt(time_stamp, 0).unwrap(); | ||
let datetime = Utc.from_utc_datetime(&utc); | ||
let time_str = datetime.format(CHRONO_TIME_FORMAT).to_string(); | ||
return time_str; | ||
} | ||
|
||
pub fn time_stamp_to_date_time(time_stamp: i64) -> String { | ||
let utc = NaiveDateTime::from_timestamp_opt(time_stamp, 0).unwrap(); | ||
let datetime = Utc.from_utc_datetime(&utc); | ||
let date_time_str = datetime.format(CHRONO_DATE_TIME_FORMAT).to_string(); | ||
return date_time_str; | ||
} | ||
|
||
pub fn date_time_to_time_stamp(date: &str) -> i64 { | ||
let date_time = NaiveDateTime::parse_from_str(date, CHRONO_DATE_TIME_FORMAT); | ||
if date_time.is_err() { | ||
return 0; | ||
} | ||
return date_time.ok().unwrap().timestamp(); | ||
} |
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 |
---|---|---|
|
@@ -6,3 +6,4 @@ pub mod scope; | |
pub mod statement; | ||
pub mod types; | ||
pub mod value; | ||
pub mod date_utils; |
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.