https://github.com/barcek/httpdt
worldwide when | easy-audit datetime library for HTTP | Rust (std only)
https://github.com/barcek/httpdt
backend datetime gmt http imf-fixdate library rust web-development
Last synced: 5 months ago
JSON representation
worldwide when | easy-audit datetime library for HTTP | Rust (std only)
- Host: GitHub
- URL: https://github.com/barcek/httpdt
- Owner: barcek
- License: mit
- Created: 2024-07-25T18:24:06.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-10T21:49:50.000Z (about 1 year ago)
- Last Synced: 2025-07-13T06:56:39.508Z (6 months ago)
- Topics: backend, datetime, gmt, http, imf-fixdate, library, rust, web-development
- Language: Rust
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# httpdt
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.
Available via [crates.io](https://crates.io/crates/httpdt):
```shell
cargo add httpdt@0.1.0
```
## Why?
For a smaller surface area and better understanding of the underlying logic when implementing a client or server. No need to audit a more extensive datetime crate to generate a single relatively straightforward output.
## How?
Instantiate a `Datetime` struct with the `new` method, then get the current timestamp for the 'Date' header field with `for_header`:
```rust
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:
```rust
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.
### Docs
The documentation is available at [docs.rs](https://docs.rs/httpdt/latest). It can be built and viewed locally in the browser with the following command:
```shell
cargo doc --open
```
## Making changes
Running the tests after making changes and adding tests to cover new behaviour is recommended.
### Tests
The unit tests and documentation example can be run with the following command:
```shell
cargo test
```
The unit test cases for each component are in the test module at the base of the corresponding source file.
## Development plan
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.
- implement a top-level error type
- revisit cross-component integer typing
- document and expose the individual components
- handle timezones, allowing for generation of server log entries in Common Log Format
- revise `SystemTime`-dependent testing
- extend test modules