implement /days/community (days since formation)
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
use axum::{Router, http::StatusCode, routing::get};
|
||||
use chrono::{NaiveDate, Utc};
|
||||
|
||||
pub fn init() -> Router {
|
||||
Router::new()
|
||||
.route("/", get(async || "root"))
|
||||
.route("/discord/member-count", get(get_member_count))
|
||||
.route("/days/community", get(get_days_since_community_formation))
|
||||
}
|
||||
|
||||
async fn get_member_count() -> (StatusCode, String) {
|
||||
@@ -15,3 +17,11 @@ async fn get_member_count() -> (StatusCode, String) {
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_days_since_community_formation() -> String {
|
||||
let formation = NaiveDate::from_ymd_opt(2020, 6, 7).unwrap();
|
||||
let today = Utc::now().date_naive();
|
||||
let days = today.signed_duration_since(formation).num_days();
|
||||
|
||||
days.to_string()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user