mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-10-30 23:24:42 +00:00 
			
		
		
		
	Parse mysql dates
This commit is contained in:
		
							
								
								
									
										1
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							| @@ -509,6 +509,7 @@ version = "0.1.0" | |||||||
| dependencies = [ | dependencies = [ | ||||||
|  "actix-rt", |  "actix-rt", | ||||||
|  "actix-web", |  "actix-web", | ||||||
|  |  "chrono", | ||||||
|  "encoding_rs", |  "encoding_rs", | ||||||
|  "futures", |  "futures", | ||||||
|  "mailchecker", |  "mailchecker", | ||||||
|   | |||||||
| @@ -18,3 +18,4 @@ percent-encoding = "2.1.0" | |||||||
| mailchecker = "3.3.6" | mailchecker = "3.3.6" | ||||||
| sha1 = "0.6.0" | sha1 = "0.6.0" | ||||||
| rand = "0.7.3" | rand = "0.7.3" | ||||||
|  | chrono = "0.4.11" | ||||||
| @@ -9,6 +9,7 @@ use mysql::prelude::Queryable; | |||||||
| use crate::data::config::DatabaseConfig; | use crate::data::config::DatabaseConfig; | ||||||
| use crate::data::error::{ExecError, ResultBoxError}; | use crate::data::error::{ExecError, ResultBoxError}; | ||||||
| use std::collections::HashMap; | use std::collections::HashMap; | ||||||
|  | use chrono::{Utc, TimeZone}; | ||||||
|  |  | ||||||
| /// Database access helper | /// Database access helper | ||||||
| /// | /// | ||||||
| @@ -213,6 +214,22 @@ impl<'a> RowResult<'a> { | |||||||
|     pub fn get_legacy_bool(&self, name: &str) -> ResultBoxError<bool> { |     pub fn get_legacy_bool(&self, name: &str) -> ResultBoxError<bool> { | ||||||
|         Ok(self.get_int64(name)? == 1) |         Ok(self.get_int64(name)? == 1) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /// Get a MYSQL date as a timestamp | ||||||
|  |     pub fn get_date_as_time(&self, name: &str) -> ResultBoxError<u64> { | ||||||
|  |         let value = self.row.get_opt(self.find_col(name)?); | ||||||
|  |         let value : Value = value.ok_or(ExecError(format!("Could not find date field {} !", name)))??; | ||||||
|  |  | ||||||
|  |         // Check if it is a date | ||||||
|  |         if let Value::Date(year, month, day, hour, minutes, seconds, mic_secs) = value { | ||||||
|  |             let dt = Utc.ymd(year as i32, month as u32, day as u32) | ||||||
|  |                 .and_hms_micro(hour as u32, minutes as u32, seconds as u32, mic_secs); | ||||||
|  |  | ||||||
|  |             return Ok(dt.timestamp() as u64); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         Err(ExecError::boxed_string(format!("Field {} could not be resolved as a date !", name))) | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -57,7 +57,7 @@ fn exec_get_user_query(query: database::QueryInfo) -> ResultBoxError<User> { | |||||||
|             public_note: res.get_optional_str("public_note")?, |             public_note: res.get_optional_str("public_note")?, | ||||||
|             block_comments_on_his_page: res.get_legacy_bool("bloquecommentaire")?, |             block_comments_on_his_page: res.get_legacy_bool("bloquecommentaire")?, | ||||||
|             allow_posts_from_friends: res.get_legacy_bool("autoriser_post_amis")?, |             allow_posts_from_friends: res.get_legacy_bool("autoriser_post_amis")?, | ||||||
|             account_creation_time: 10,//TODO : parse date |             account_creation_time: res.get_date_as_time("date_creation")? | ||||||
|         }) |         }) | ||||||
|     }) |     }) | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user