cookie_expire

Crates.iocookie_expire
lib.rscookie_expire
version0.1.1
created_at2025-02-27 09:25:49.102923+00
updated_at2025-02-27 09:25:49.102923+00
descriptioncookie_expire
homepagehttps://github.com/i18n-site/rust/tree/dev/cookie_expire
repositoryhttps://github.com/i18n-site/rust.git
max_upload_size
id1571530
size26,133
i18n.site (i18nsite)

documentation

README

cookie_expire

use chrono::{DateTime, Utc};
use coarsetime::Clock;

pub fn cookie_expire_with_days(days: u64) -> String {
  let now = Clock::now_since_epoch();
  let future_time = now + coarsetime::Duration::from_secs(days * 24 * 60 * 60);
  let datetime = DateTime::<Utc>::from_timestamp(future_time.as_secs() as i64, 0).unwrap();
  datetime.format("%a, %d %b %Y %H:%M:%S GMT").to_string()
}

pub fn cookie_expire() -> String {
  // 从 Chrome M104(2022 年 8 月)开始,Cookie 所设置的有效期不能超过 400 天。 https://developer.chrome.com/blog/cookie-max-age-expires
  cookie_expire_with_days(400)
}

About

This project is an open-source component of i18n.site ⋅ Internationalization Solution.

关于

本项目为 i18n.site ⋅ 国际化解决方案 的开源组件。

Commit count: 68

cargo fmt