rust-carbon
rust-carbon is thin wrapper of rust-time. Utility for handling date and time.
Usage
Add rust-carbon to your Cargo.toml.
[]
= "0.1.*"
And put this in your crate root.
extern crate carbon;
Overview
rust-carbon provides start_of()
and end_of()
to get datetime.
And you can modify datetime by second
,minute
,hour
,day
, and month
.
// import carbon first
use *;
// now assume that it is 2015-01-15 01:30:30.500000000
now.start_of.second;
// => return carbon::DateTime for 2015-01-15 01:30:30.000000000
now.start_of.minute;
// => return carbon::DateTime for 2015-01-15 01:30:00.000000000
now.start_of.hour;
// => return carbon::DateTime for 2015-01-15 01:00:00.000000000
now.start_of.day;
// => return carbon::DateTime for 2015-01-15 00:00:00.000000000
now.start_of.month;
// => return carbon::DateTime for 2015-01-01 00:00:00.000000000
now.end_of.second;
// => return carbon::DateTime for 2015-01-15 01:30:30.999999999
now.end_of.minute;
// => return carbon::DateTime for 2015-01-15 01:30:59.999999999
now.end_of.hour;
// => return carbon::DateTime for 2015-01-15 01:59:59.999999999
now.end_of.day;
// => return carbon::DateTime for 2015-01-15 23:59:59.999999999
now.end_of.month;
// => return carbon::DateTime for 2015-01-31 23:59:59.999999999
More sample codes
Chaining method calls
// now assume that it is 2015-01-15 01:30:30.500000000
now.start_of.day.end_of.hour;
// => return carbon::DateTime for 2015-01-15 00:59:59.999999999
Directly specify time and set now
the time. It is useful for testing.
// carbon::DateTime for 2015-01-01 00:00:00
let tm = Tm ;
}
let test_now = create_from_tm;
set_test_now;
now;
// => return carbon::DateTime for 2015-01-01 00:00:00
rust-carbon is thin wrapper of rust-time. You can access time::Tm
easily.
// now assume that it is 2015-01-15 01:30:30.500000000
now.tm.strftime.ok.unwrap.to_string;
// => return string "2015-01-15 01:30:30"
use ;
let hour = hours;
now.tm.add
// return time::Tm for 2015-01-15 02:30:30.500000000
Known Issue
- rust-carbon can only deal UTC.
- enable to modify
start_of().year()