Skip to content

Commit a0803b0

Browse files
oschwaldclaude
andcommitted
Add Metadata::build_time() method
Adds a convenience method to convert the build_epoch Unix timestamp to a SystemTime, matching the Go v2 library's BuildTime() method. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 14e7872 commit a0803b0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
- `decode_path()` errors now include path context showing where navigation failed
4646
(e.g., `path: /city/names/0`), making it easier to debug issues with nested data.
4747
- `Metadata` and `WithinOptions` now implement `PartialEq` and `Eq` traits.
48+
- Added `Metadata::build_time()` method to convert `build_epoch` to `SystemTime`.
4849
- Added `verify()` method for comprehensive database validation. Validates
4950
metadata, search tree structure, data section separator, and data records.
5051
Useful for validating database files after download or generation.

src/metadata.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,23 @@ pub struct Metadata {
2626
/// Size of each record in bits (24, 28, or 32).
2727
pub record_size: u16,
2828
}
29+
30+
impl Metadata {
31+
/// Returns the database build time as a `SystemTime`.
32+
///
33+
/// This converts the `build_epoch` Unix timestamp to a `SystemTime`.
34+
///
35+
/// # Example
36+
///
37+
/// ```
38+
/// use maxminddb::Reader;
39+
///
40+
/// let reader = Reader::open_readfile("test-data/test-data/GeoIP2-City-Test.mmdb").unwrap();
41+
/// let build_time = reader.metadata.build_time();
42+
/// println!("Database built: {:?}", build_time);
43+
/// ```
44+
#[must_use]
45+
pub fn build_time(&self) -> std::time::SystemTime {
46+
std::time::UNIX_EPOCH + std::time::Duration::from_secs(self.build_epoch)
47+
}
48+
}

0 commit comments

Comments
 (0)