Crates.io | mwtimestamp |
lib.rs | mwtimestamp |
version | 0.1.1 |
source | src |
created_at | 2023-11-26 05:02:27.816304 |
updated_at | 2024-06-02 15:23:36.179698 |
description | parsing and formatting for MediaWiki timestamps |
homepage | https://www.mediawiki.org/wiki/mwbot-rs |
repository | https://gitlab.wikimedia.org/repos/mwbot-rs/mwbot/ |
max_upload_size | |
id | 1048807 |
size | 45,003 |
mwtimestamp
is a library for parsing and formatting MediaWiki
timestamps, powered by chrono
.
The MediaWiki API typically produces ISO 8601 timestamps. In some cases, like protection or block expiry, it may alternatively return the string "infinity" to represent that there is no end period.
use mwtimestamp::{Expiry, Timestamp};
// Deserializing a fixed timestamp
let finite: Timestamp = serde_json::from_str("\"2001-01-15T14:56:00Z\"").unwrap();
assert_eq!(
finite.date_naive(),
chrono::NaiveDate::from_ymd_opt(2001, 1, 15).unwrap(),
);
// Deserializing an infinite timestamp
let infinity: Expiry = serde_json::from_str("\"infinity\"").unwrap();
assert!(infinity.is_infinity());
mwtimestamp
is a part of the mwbot-rs
project.
We're always looking for new contributors, please reach out
if you're interested!
This crate is released under GPL-3.0-or-later. See COPYING for details.