-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
136 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
[package] | ||
name = "file-ext" | ||
version = "8.0.1" | ||
version = "9.0.0" | ||
authors = ["Bohdan Tsap <[email protected]>"] | ||
repository = "https://github.com/bohdaq/file-ext" | ||
description = "Collection of utility functions to work with files" | ||
edition = "2021" | ||
license = "MIT OR Apache-2.0 OR ISC OR LGPL-3.0-or-later OR CC-BY-4.0" | ||
categories = ["filesystem", "os", "embedded"] | ||
keywords = ["file", "read", "create", "update", "delete"] | ||
rust-version = "1.65" | ||
rust-version = "1.66" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
rust-web-server = "8.0.0" |
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,27 @@ | ||
use std::time::{SystemTime, UNIX_EPOCH}; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
pub struct DateTimeExt; | ||
|
||
impl DateTimeExt { | ||
pub fn _now_unix_epoch_nanos() -> u128 { | ||
let now = SystemTime::now(); | ||
let nanos = DateTimeExt::_system_time_to_unix_nanos(now); | ||
nanos | ||
} | ||
|
||
pub fn _system_time_to_unix_nanos(system_time: SystemTime) -> u128 { | ||
let boxed_duration = system_time.duration_since(UNIX_EPOCH); | ||
if boxed_duration.is_err() { | ||
eprintln!("unable to get duration from system time {}", boxed_duration.err().unwrap()); | ||
let nanos = 0 as u128; | ||
return nanos | ||
} | ||
|
||
let nanos = boxed_duration.unwrap().as_nanos(); | ||
nanos | ||
} | ||
|
||
} |
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,16 @@ | ||
use std::time::SystemTime; | ||
use crate::date_time_ext::DateTimeExt; | ||
|
||
|
||
#[test] | ||
fn system_to_nanos() { | ||
let now = SystemTime::now(); | ||
let nanos = DateTimeExt::_system_time_to_unix_nanos(now); | ||
assert_ne!(nanos, 0); | ||
} | ||
|
||
#[test] | ||
fn now_as_nanos() { | ||
let nanos = DateTimeExt::_now_unix_epoch_nanos(); | ||
assert_ne!(nanos, 0); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#[cfg(test)] | ||
mod tests; | ||
|
||
pub struct Symbol { | ||
pub new_line_carriage_return: &'static str, | ||
pub new_line: &'static str, | ||
pub carriage_return: &'static str, | ||
pub empty_string: &'static str, | ||
pub whitespace: &'static str, | ||
pub equals: &'static str, | ||
pub comma: &'static str, | ||
pub hyphen: &'static str, | ||
pub slash: &'static str, | ||
pub semicolon: &'static str, | ||
pub colon: &'static str, | ||
pub number_sign: &'static str, | ||
pub opening_square_bracket: &'static str, | ||
pub closing_square_bracket: &'static str, | ||
pub quotation_mark: &'static str, | ||
pub underscore: &'static str, | ||
pub single_quote: &'static str, | ||
} | ||
|
||
pub const SYMBOL: Symbol = Symbol { | ||
new_line: "\n", | ||
carriage_return: "\r", | ||
new_line_carriage_return: "\r\n", | ||
empty_string: "", | ||
whitespace: " ", | ||
equals: "=", | ||
comma: ",", | ||
hyphen: "-", | ||
slash: "/", | ||
semicolon: ";", | ||
colon: ":", | ||
number_sign: "#", | ||
opening_square_bracket: "[", | ||
closing_square_bracket: "]", | ||
quotation_mark: "\"", | ||
underscore: "_", | ||
single_quote: "'", | ||
}; |
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,16 @@ | ||
use crate::symbol::SYMBOL; | ||
|
||
#[test] | ||
fn symbol_check() { | ||
assert_eq!(SYMBOL.new_line, "\n"); | ||
assert_eq!(SYMBOL.carriage_return, "\r"); | ||
assert_eq!(SYMBOL.new_line_carriage_return, "\r\n"); | ||
assert_eq!(SYMBOL.empty_string, ""); | ||
assert_eq!(SYMBOL.whitespace, " "); | ||
assert_eq!(SYMBOL.equals, "="); | ||
assert_eq!(SYMBOL.comma, ","); | ||
assert_eq!(SYMBOL.hyphen, "-"); | ||
assert_eq!(SYMBOL.slash, "/"); | ||
assert_eq!(SYMBOL.semicolon, ";"); | ||
assert_eq!(SYMBOL.colon, ":"); | ||
} |
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