Crates.io | httpdt |
lib.rs | httpdt |
version | 0.1.0 |
source | src |
created_at | 2024-07-25 18:46:52.045733 |
updated_at | 2024-07-25 18:46:52.045733 |
description | datetime library for HTTP clients and servers |
homepage | |
repository | https://github.com/barcek/httpdt/ |
max_upload_size | |
id | 1315341 |
size | 29,771 |
A datetime library for HTTP clients and servers.
Generates timestamps for use in the HTTP Date header, the only format required for implementation of HTTP.
Calculates with a focus on clarity from SystemTime
, with no external dependencies, and provides for updates to previously generated datetimes for speed.
For simplicity and fuller comprehension when implementing a client or server. No need to audit a more extensive datetime crate to generate a single relatively straightforward output.
Instantiate a Datetime
struct with the new
method, then get the current timestamp for the 'Date' header field with for_header
:
use httpdt::Datetime;
let timestamp = Datetime::new()?
.for_header();
To reduce computation, an initial instance can be used as the basis for successive new timestamps via the now
method:
use httpdt::Datetime;
let dt = Datetime::new()?;
let ts_initial = dt
.for_header();
// ...
let ts_updated = dt
.now()?
.for_header();
The default
method provides a Datetime
instance corresponding to the Unix epoch, the raw
method the number of seconds since the epoch.
The documentation can be built and viewed in the browser with the following command:
cargo doc --open
Running the tests after making changes and adding tests to cover new behaviour is recommended.
The unit tests and documentation example can be run with the following command:
cargo test
The unit test cases for each component are in the test module at the base of the corresponding source file.
The following are the expected next steps in the development of the code base. The general medium-term aim is a clear, robust and efficient datetime resource for fuller HTTP implementations. Pull requests are welcome for these and other potential improvements.
SystemTime
-dependent testing