Skip to main content

time

Function time 

Source
pub fn time(at: impl UnixSeconds) -> Time
Expand description

Shows at in each reader’s time zone and language: <t:1618953630>.

Without a style Discord uses LongDateShortTime (D-213). Discord counts whole seconds, so a fraction is dropped (rounding down).

discord.js counterpart: time.

§Examples

use djs_formatters::{TimestampStyle, time};
use djs_model::util::Timestamp;

assert_eq!(time(1_618_953_630).to_string(), "<t:1618953630>");
assert_eq!(time(1_618_953_630).style(TimestampStyle::RelativeTime).to_string(), "<t:1618953630:R>");

let sent = Timestamp::parse("2021-04-20T21:20:30.250+00:00").unwrap();
assert_eq!(time(sent).style(TimestampStyle::ShortDate).to_string(), "<t:1618953630:d>");

// Now, as "in a few seconds" / "a few seconds ago":
let now = time(std::time::SystemTime::now()).style(TimestampStyle::RelativeTime);