refactor(mmime): rustify mailimf_data_time

This commit is contained in:
dignifiedquire
2019-09-28 14:09:53 -06:00
parent 2abfd037ca
commit c78753e8fa
6 changed files with 204 additions and 221 deletions

View File

@@ -207,15 +207,16 @@ unsafe fn display_mime_fields(mut fields: *mut mailmime_fields) {
unsafe fn display_date_time(mut d: *mut mailimf_date_time) {
print!(
"{:02}/{:02}/{:02} {:02}:{:02}:{:02} +{:04}",
(*d).dt_day,
(*d).dt_month,
(*d).dt_year,
(*d).dt_hour,
(*d).dt_min,
(*d).dt_sec,
(*d).dt_zone,
(*d).day,
(*d).month,
(*d).year,
(*d).hour,
(*d).min,
(*d).sec,
(*d).zone,
);
}
unsafe fn display_orig_date(mut orig_date: *mut mailimf_orig_date) {
display_date_time((*orig_date).dt_date_time);
}

View File

@@ -2849,16 +2849,16 @@ pub unsafe fn mailimf_date_time_parse(
let mut cur_token: size_t = 0;
let mut day_of_week: libc::c_int = 0;
let mut date_time: *mut mailimf_date_time = 0 as *mut mailimf_date_time;
let mut day: libc::c_int = 0;
let mut month: libc::c_int = 0;
let mut year: libc::c_int = 0;
let mut hour: libc::c_int = 0;
let mut min: libc::c_int = 0;
let mut sec: libc::c_int = 0;
let mut zone: libc::c_int = 0;
let mut day = 0;
let mut month = 0;
let mut year = 0;
let mut hour = 0;
let mut min = 0;
let mut sec = 0;
let mut zone = 0;
let mut r: libc::c_int = 0;
cur_token = *indx;
day_of_week = -1i32;
day_of_week = -1;
r = mailimf_day_of_week_parse(message, length, &mut cur_token, &mut day_of_week);
if r == MAILIMF_NO_ERROR as libc::c_int {
r = mailimf_comma_parse(message, length, &mut cur_token);
@@ -2870,9 +2870,9 @@ pub unsafe fn mailimf_date_time_parse(
} else if r != MAILIMF_ERROR_PARSE as libc::c_int {
return r;
}
day = 0i32;
month = 0i32;
year = 0i32;
day = 0;
month = 0;
year = 0;
r = mailimf_date_parse(
message,
length,
@@ -2897,10 +2897,10 @@ pub unsafe fn mailimf_date_time_parse(
if r != MAILIMF_NO_ERROR as libc::c_int {
return r;
}
hour = 0i32;
min = 0i32;
sec = 0i32;
zone = 0i32;
hour = 0;
min = 0;
sec = 0;
zone = 0;
r = mailimf_time_parse(
message,
length,
@@ -2925,16 +2925,16 @@ unsafe fn mailimf_time_parse(
mut message: *const libc::c_char,
mut length: size_t,
mut indx: *mut size_t,
mut phour: *mut libc::c_int,
mut pmin: *mut libc::c_int,
mut psec: *mut libc::c_int,
mut pzone: *mut libc::c_int,
mut phour: *mut u32,
mut pmin: *mut u32,
mut psec: *mut u32,
mut pzone: *mut i32,
) -> libc::c_int {
let mut cur_token: size_t = 0;
let mut hour: libc::c_int = 0;
let mut min: libc::c_int = 0;
let mut sec: libc::c_int = 0;
let mut zone: libc::c_int = 0;
let mut hour = 0;
let mut min = 0;
let mut sec = 0;
let mut zone = 0;
let mut r: libc::c_int = 0;
cur_token = *indx;
r = mailimf_cfws_parse(message, length, &mut cur_token);
@@ -2959,7 +2959,7 @@ unsafe fn mailimf_time_parse(
r = mailimf_zone_parse(message, length, &mut cur_token, &mut zone);
if !(r == MAILIMF_NO_ERROR as libc::c_int) {
if r == MAILIMF_ERROR_PARSE as libc::c_int {
zone = 0i32
zone = 0
} else {
return r;
}
@@ -2969,31 +2969,32 @@ unsafe fn mailimf_time_parse(
*psec = sec;
*pzone = zone;
*indx = cur_token;
return MAILIMF_NO_ERROR as libc::c_int;
MAILIMF_NO_ERROR as libc::c_int
}
unsafe fn mailimf_zone_parse(
mut message: *const libc::c_char,
mut length: size_t,
mut indx: *mut size_t,
mut result: *mut libc::c_int,
mut result: *mut i32,
) -> libc::c_int {
let mut zone: libc::c_int = 0;
let mut zone = 0;
let mut sign: libc::c_int = 0;
let mut cur_token: size_t = 0;
let mut r: libc::c_int = 0;
let mut value: uint32_t = 0;
let mut value = 0;
cur_token = *indx;
if cur_token.wrapping_add(1i32 as libc::size_t) < length {
if *message.offset(cur_token as isize) as libc::c_int == 'U' as i32
&& *message.offset(cur_token.wrapping_add(1i32 as libc::size_t) as isize) as libc::c_int
== 'T' as i32
{
*result = 1i32;
*result = 1;
*indx = cur_token.wrapping_add(2i32 as libc::size_t);
return MAILIMF_NO_ERROR as libc::c_int;
}
}
zone = 0i32;
zone = 0;
if cur_token.wrapping_add(2i32 as libc::size_t) < length {
let mut state: libc::c_int = 0;
state = STATE_ZONE_1 as libc::c_int;
@@ -3024,7 +3025,7 @@ unsafe fn mailimf_zone_parse(
as size_t as size_t;
state = STATE_ZONE_CONT as libc::c_int
} else {
zone = 0i32;
zone = 0;
state = STATE_ZONE_OK as libc::c_int
}
} else {
@@ -3032,19 +3033,19 @@ unsafe fn mailimf_zone_parse(
}
}
69 => {
zone = -5i32;
zone = -5;
state = STATE_ZONE_2 as libc::c_int
}
67 => {
zone = -6i32;
zone = -6;
state = STATE_ZONE_2 as libc::c_int
}
77 => {
zone = -7i32;
zone = -7;
state = STATE_ZONE_2 as libc::c_int
}
80 => {
zone = -8i32;
zone = -8;
state = STATE_ZONE_2 as libc::c_int
}
_ => state = STATE_ZONE_CONT as libc::c_int,
@@ -3066,7 +3067,7 @@ unsafe fn mailimf_zone_parse(
as libc::c_int
== 'T' as i32
{
zone *= 100i32;
zone *= 100;
state = STATE_ZONE_OK as libc::c_int
} else {
state = STATE_ZONE_ERR as libc::c_int
@@ -3107,7 +3108,7 @@ unsafe fn mailimf_zone_parse(
if r != MAILIMF_NO_ERROR as libc::c_int {
return r;
}
zone = value.wrapping_mul(sign as libc::c_uint) as libc::c_int;
zone = value.wrapping_mul(sign as libc::c_uint) as i32;
*indx = cur_token;
*result = zone;
return MAILIMF_NO_ERROR as libc::c_int;
@@ -3192,13 +3193,13 @@ unsafe fn mailimf_time_of_day_parse(
mut message: *const libc::c_char,
mut length: size_t,
mut indx: *mut size_t,
mut phour: *mut libc::c_int,
mut pmin: *mut libc::c_int,
mut psec: *mut libc::c_int,
mut phour: *mut u32,
mut pmin: *mut u32,
mut psec: *mut u32,
) -> libc::c_int {
let mut hour: libc::c_int = 0;
let mut min: libc::c_int = 0;
let mut sec: libc::c_int = 0;
let mut hour = 0;
let mut min = 0;
let mut sec = 0;
let mut cur_token: size_t = 0;
let mut r: libc::c_int = 0;
cur_token = *indx;
@@ -3221,7 +3222,7 @@ unsafe fn mailimf_time_of_day_parse(
return r;
}
} else if r == MAILIMF_ERROR_PARSE as libc::c_int {
sec = 0i32
sec = 0;
} else {
return r;
}
@@ -3235,72 +3236,75 @@ unsafe fn mailimf_second_parse(
mut message: *const libc::c_char,
mut length: size_t,
mut indx: *mut size_t,
mut result: *mut libc::c_int,
mut result: *mut u32,
) -> libc::c_int {
let mut second: uint32_t = 0;
let mut second = 0;
let mut r: libc::c_int = 0;
r = mailimf_number_parse(message, length, indx, &mut second);
if r != MAILIMF_NO_ERROR as libc::c_int {
return r;
}
*result = second as libc::c_int;
return MAILIMF_NO_ERROR as libc::c_int;
*result = second as u32;
MAILIMF_NO_ERROR as libc::c_int
}
unsafe fn mailimf_minute_parse(
mut message: *const libc::c_char,
mut length: size_t,
mut indx: *mut size_t,
mut result: *mut libc::c_int,
mut result: *mut u32,
) -> libc::c_int {
let mut minute: uint32_t = 0;
let mut minute = 0;
let mut r: libc::c_int = 0;
r = mailimf_number_parse(message, length, indx, &mut minute);
if r != MAILIMF_NO_ERROR as libc::c_int {
return r;
}
*result = minute as libc::c_int;
return MAILIMF_NO_ERROR as libc::c_int;
*result = minute as u32;
MAILIMF_NO_ERROR as libc::c_int
}
unsafe fn mailimf_hour_parse(
mut message: *const libc::c_char,
mut length: size_t,
mut indx: *mut size_t,
mut result: *mut libc::c_int,
mut result: *mut u32,
) -> libc::c_int {
let mut hour: uint32_t = 0;
let mut hour = 0;
let mut r: libc::c_int = 0;
r = mailimf_number_parse(message, length, indx, &mut hour);
if r != MAILIMF_NO_ERROR as libc::c_int {
return r;
}
*result = hour as libc::c_int;
return MAILIMF_NO_ERROR as libc::c_int;
*result = hour as u32;
MAILIMF_NO_ERROR as libc::c_int
}
unsafe fn mailimf_broken_date_parse(
mut message: *const libc::c_char,
mut length: size_t,
mut indx: *mut size_t,
mut pday: *mut libc::c_int,
mut pmonth: *mut libc::c_int,
mut pyear: *mut libc::c_int,
mut pday: *mut u32,
mut pmonth: *mut u32,
mut pyear: *mut i32,
) -> libc::c_int {
let mut cur_token: size_t = 0;
let mut day: libc::c_int = 0;
let mut month: libc::c_int = 0;
let mut year: libc::c_int = 0;
let mut day = 0;
let mut month = 0;
let mut year = 0;
let mut r: libc::c_int = 0;
cur_token = *indx;
month = 1i32;
month = 1;
r = mailimf_month_parse(message, length, &mut cur_token, &mut month);
if r != MAILIMF_NO_ERROR as libc::c_int {
return r;
}
day = 1i32;
day = 1;
r = mailimf_day_parse(message, length, &mut cur_token, &mut day);
if r != MAILIMF_NO_ERROR as libc::c_int {
return r;
}
year = 2001i32;
year = 2001;
r = mailimf_year_parse(message, length, &mut cur_token, &mut year);
if r != MAILIMF_NO_ERROR as libc::c_int {
return r;
@@ -3315,9 +3319,9 @@ unsafe fn mailimf_year_parse(
mut message: *const libc::c_char,
mut length: size_t,
mut indx: *mut size_t,
mut result: *mut libc::c_int,
mut result: *mut i32,
) -> libc::c_int {
let mut number: uint32_t = 0;
let mut number = 0;
let mut cur_token: size_t = 0;
let mut r: libc::c_int = 0;
cur_token = *indx;
@@ -3330,17 +3334,18 @@ unsafe fn mailimf_year_parse(
return r;
}
*indx = cur_token;
*result = number as libc::c_int;
return MAILIMF_NO_ERROR as libc::c_int;
*result = number as i32;
MAILIMF_NO_ERROR as libc::c_int
}
unsafe fn mailimf_day_parse(
mut message: *const libc::c_char,
mut length: size_t,
mut indx: *mut size_t,
mut result: *mut libc::c_int,
mut result: *mut u32,
) -> libc::c_int {
let mut cur_token: size_t = 0;
let mut day: uint32_t = 0;
let mut day = 0;
let mut r: libc::c_int = 0;
cur_token = *indx;
r = mailimf_cfws_parse(message, length, &mut cur_token);
@@ -3351,18 +3356,19 @@ unsafe fn mailimf_day_parse(
if r != MAILIMF_NO_ERROR as libc::c_int {
return r;
}
*result = day as libc::c_int;
*result = day as u32;
*indx = cur_token;
return MAILIMF_NO_ERROR as libc::c_int;
MAILIMF_NO_ERROR as libc::c_int
}
unsafe fn mailimf_month_parse(
mut message: *const libc::c_char,
mut length: size_t,
mut indx: *mut size_t,
mut result: *mut libc::c_int,
mut result: *mut u32,
) -> libc::c_int {
let mut cur_token: size_t = 0;
let mut month: libc::c_int = 0;
let mut month = 0;
let mut r: libc::c_int = 0;
cur_token = *indx;
r = mailimf_cfws_parse(message, length, &mut cur_token);
@@ -3375,38 +3381,41 @@ unsafe fn mailimf_month_parse(
}
*result = month;
*indx = cur_token;
return MAILIMF_NO_ERROR as libc::c_int;
MAILIMF_NO_ERROR as libc::c_int
}
unsafe fn mailimf_month_name_parse(
mut message: *const libc::c_char,
mut length: size_t,
mut indx: *mut size_t,
mut result: *mut libc::c_int,
mut result: *mut u32,
) -> libc::c_int {
let mut cur_token: size_t = 0;
let mut month: libc::c_int = 0;
let mut guessed_month: libc::c_int = 0;
let mut r: libc::c_int = 0;
let mut month: u32 = 0;
cur_token = *indx;
guessed_month = guess_month(message, length, cur_token);
if guessed_month == -1i32 {
let guessed_month = guess_month(message, length, cur_token);
if guessed_month < 0 {
return MAILIMF_ERROR_PARSE as libc::c_int;
}
r = mailimf_token_case_insensitive_len_parse(
let r = mailimf_token_case_insensitive_len_parse(
message,
length,
&mut cur_token,
month_names[(guessed_month - 1i32) as usize].str_0,
strlen(month_names[(guessed_month - 1i32) as usize].str_0),
month_names[(guessed_month - 1) as usize].str_0,
strlen(month_names[(guessed_month - 1) as usize].str_0),
);
if r != MAILIMF_NO_ERROR as libc::c_int {
return r;
}
month = guessed_month;
month = guessed_month as u32;
*result = month;
*indx = cur_token;
return MAILIMF_NO_ERROR as libc::c_int;
MAILIMF_NO_ERROR as libc::c_int
}
/*
month-name = "Jan" / "Feb" / "Mar" / "Apr" /
"May" / "Jun" / "Jul" / "Aug" /
@@ -3543,27 +3552,27 @@ unsafe fn mailimf_date_parse(
mut message: *const libc::c_char,
mut length: size_t,
mut indx: *mut size_t,
mut pday: *mut libc::c_int,
mut pmonth: *mut libc::c_int,
mut pyear: *mut libc::c_int,
mut pday: *mut u32,
mut pmonth: *mut u32,
mut pyear: *mut i32,
) -> libc::c_int {
let mut cur_token: size_t = 0;
let mut day: libc::c_int = 0;
let mut month: libc::c_int = 0;
let mut year: libc::c_int = 0;
let mut day = 0;
let mut month = 0;
let mut year = 0;
let mut r: libc::c_int = 0;
cur_token = *indx;
day = 1i32;
day = 1;
r = mailimf_day_parse(message, length, &mut cur_token, &mut day);
if r != MAILIMF_NO_ERROR as libc::c_int {
return r;
}
month = 1i32;
month = 1;
r = mailimf_month_parse(message, length, &mut cur_token, &mut month);
if r != MAILIMF_NO_ERROR as libc::c_int {
return r;
}
year = 2001i32;
year = 2001;
r = mailimf_year_parse(message, length, &mut cur_token, &mut year);
if r != MAILIMF_NO_ERROR as libc::c_int {
return r;
@@ -3631,7 +3640,7 @@ unsafe fn mailimf_day_name_parse(
day_of_week = guessed_day;
*result = day_of_week;
*indx = cur_token;
return MAILIMF_NO_ERROR as libc::c_int;
MAILIMF_NO_ERROR as libc::c_int
}
static mut day_names: [mailimf_token_value; 7] = [
mailimf_token_value {

View File

@@ -4,48 +4,35 @@ use crate::clist::*;
use crate::other::*;
/*
IMPORTANT NOTE:
IMPORTANT NOTE:
All allocation functions will take as argument allocated data
and will store these data in the structure they will allocate.
Data should be persistant during all the use of the structure
and will be freed by the free function of the structure
All allocation functions will take as argument allocated data
and will store these data in the structure they will allocate.
Data should be persistant during all the use of the structure
and will be freed by the free function of the structure
allocation functions will return NULL on failure
allocation functions will return NULL on failure
*/
/*
mailimf_date_time is a date
- day is the day of month (1 to 31)
- month (1 to 12)
- year (4 digits)
- hour (0 to 23)
- min (0 to 59)
- sec (0 to 59)
- zone (this is the decimal value that we can read, for example:
for "-0200", the value is -200)
*/
#[derive(Copy, Clone, Debug)]
#[repr(C)]
/// Date
/// - day is the day of month (1 to 31)
/// - month (1 to 12)
/// - year (4 digits)
/// - hour (0 to 23)
/// - min (0 to 59)
/// - sec (0 to 59)
/// - zone (this is the decimal value that we can read, for example:
// for "-0200", the value is -200)
#[derive(Clone, Debug)]
pub struct mailimf_date_time {
pub dt_day: libc::c_int,
pub dt_month: libc::c_int,
pub dt_year: libc::c_int,
pub dt_hour: libc::c_int,
pub dt_min: libc::c_int,
pub dt_sec: libc::c_int,
pub dt_zone: libc::c_int,
pub day: u32,
pub month: u32,
pub year: i32,
pub hour: u32,
pub min: u32,
pub sec: u32,
pub zone: i32,
}
/* this is the type of address */
/* if this is a group
(group_name: address1@domain1,
address2@domain2; ) */
/// An address, either for a mailbox or a group.
#[derive(Debug, Clone, Copy)]
@@ -438,34 +425,35 @@ pub const MAILIMF_FIELD_RETURN_PATH: unnamed_2 = 1;
pub type unnamed_2 = libc::c_uint;
/* on parse error */
pub const MAILIMF_FIELD_NONE: unnamed_2 = 0;
#[no_mangle]
pub unsafe fn mailimf_date_time_new(
mut dt_day: libc::c_int,
mut dt_month: libc::c_int,
mut dt_year: libc::c_int,
mut dt_hour: libc::c_int,
mut dt_min: libc::c_int,
mut dt_sec: libc::c_int,
mut dt_zone: libc::c_int,
day: u32,
month: u32,
year: i32,
hour: u32,
min: u32,
sec: u32,
zone: i32,
) -> *mut mailimf_date_time {
let mut date_time: *mut mailimf_date_time = 0 as *mut mailimf_date_time;
date_time = malloc(::std::mem::size_of::<mailimf_date_time>() as libc::size_t)
as *mut mailimf_date_time;
if date_time.is_null() {
return 0 as *mut mailimf_date_time;
}
(*date_time).dt_day = dt_day;
(*date_time).dt_month = dt_month;
(*date_time).dt_year = dt_year;
(*date_time).dt_hour = dt_hour;
(*date_time).dt_min = dt_min;
(*date_time).dt_sec = dt_sec;
(*date_time).dt_zone = dt_zone;
return date_time;
let dt = mailimf_date_time {
day,
month,
year,
hour,
min,
sec,
zone,
};
Box::into_raw(Box::new(dt))
}
pub unsafe fn mailimf_date_time_free(mut date_time: *mut mailimf_date_time) {
free(date_time as *mut libc::c_void);
pub unsafe fn mailimf_date_time_free(date_time: *mut mailimf_date_time) {
if date_time.is_null() {
return;
}
let _ = Box::from_raw(date_time);
}
pub fn mailimf_address_new_mailbox(ad_mailbox: *mut mailimf_mailbox) -> *mut mailimf_address {

View File

@@ -1581,22 +1581,18 @@ unsafe fn mailimf_date_time_write_driver(
mut col: *mut libc::c_int,
mut date_time: *mut mailimf_date_time,
) -> libc::c_int {
let wday = dayofweek(
(*date_time).dt_year,
(*date_time).dt_month,
(*date_time).dt_day,
);
let wday = dayofweek((*date_time).year, (*date_time).month, (*date_time).day);
let date_str = format!(
"{}, {} {} {} {:02}:{:02}:{:02} {:+05}",
week_of_day_str[wday as usize],
(*date_time).dt_day,
month_str[((*date_time).dt_month - 1i32) as usize],
(*date_time).dt_year,
(*date_time).dt_hour,
(*date_time).dt_min,
(*date_time).dt_sec,
(*date_time).dt_zone,
wday,
(*date_time).day,
month_str[((*date_time).month - 1) as usize],
(*date_time).year,
(*date_time).hour,
(*date_time).min,
(*date_time).sec,
(*date_time).zone,
);
let date_str_c = std::ffi::CString::new(date_str).unwrap();
let r = mailimf_string_write_driver(
@@ -1611,27 +1607,16 @@ unsafe fn mailimf_date_time_write_driver(
}
return MAILIMF_NO_ERROR as libc::c_int;
}
static mut month_str: [&'static str; 12] = [
static mut month_str: [&str; 12] = [
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
];
static mut week_of_day_str: [&'static str; 7] = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
/* 0 = Sunday */
/* y > 1752 */
unsafe fn dayofweek(
mut year: libc::c_int,
mut month: libc::c_int,
mut day: libc::c_int,
) -> libc::c_int {
static mut offset: [libc::c_int; 12] = [
0i32, 3i32, 2i32, 5i32, 0i32, 3i32, 5i32, 1i32, 4i32, 6i32, 2i32, 4i32,
];
year -= (month < 3i32) as libc::c_int;
return (year + year / 4i32 - year / 100i32
+ year / 400i32
+ offset[(month - 1i32) as usize]
+ day)
% 7i32;
fn dayofweek(year: i32, month: u32, day: u32) -> String {
chrono::NaiveDate::from_ymd(year, month, day)
.format("%a")
.to_string()
}
unsafe fn mailimf_resent_msg_id_write_driver(
mut do_write: Option<
unsafe fn(_: *mut libc::c_void, _: *const libc::c_char, _: size_t) -> libc::c_int,

View File

@@ -1646,12 +1646,12 @@ pub fn mailimf_get_date(t: i64) -> *mut mailimf_date_time {
unsafe {
mailimf_date_time_new(
lt.day() as libc::c_int,
lt.month() as libc::c_int,
lt.year() as libc::c_int,
lt.hour() as libc::c_int,
lt.minute() as libc::c_int,
lt.second() as libc::c_int,
lt.day(),
lt.month(),
lt.year(),
lt.hour(),
lt.minute(),
lt.second(),
off,
)
}
@@ -1691,16 +1691,16 @@ mod tests {
let now_local = Local.from_utc_datetime(&now_utc.naive_local());
let t_local = now_local.timestamp();
let converted = unsafe { *mailimf_get_date(t_local as i64) };
let converted = unsafe { &*mailimf_get_date(t_local as i64) };
assert_eq!(converted.dt_day as u32, now_local.day());
assert_eq!(converted.dt_month as u32, now_local.month());
assert_eq!(converted.dt_year, now_local.year());
assert_eq!(converted.dt_hour as u32, now_local.hour());
assert_eq!(converted.dt_min as u32, now_local.minute());
assert_eq!(converted.dt_sec as u32, now_local.second());
assert_eq!(converted.day, now_local.day());
assert_eq!(converted.month, now_local.month());
assert_eq!(converted.year, now_local.year());
assert_eq!(converted.hour, now_local.hour());
assert_eq!(converted.min, now_local.minute());
assert_eq!(converted.sec, now_local.second());
assert_eq!(
converted.dt_zone,
converted.zone,
(now_local.offset().local_minus_utc() / (60 * 60)) * 100
);
}

View File

@@ -219,24 +219,24 @@ pub(crate) fn dc_str_to_color(s: impl AsRef<str>) -> u32 {
/* the result is UTC or DC_INVALID_TIMESTAMP */
pub(crate) fn dc_timestamp_from_date(date_time: *mut mailimf_date_time) -> i64 {
assert!(!date_time.is_null());
let dt = unsafe { *date_time };
let dt = unsafe { &*date_time };
let sec = dt.dt_sec;
let min = dt.dt_min;
let hour = dt.dt_hour;
let day = dt.dt_day;
let month = dt.dt_month;
let year = dt.dt_year;
let sec = dt.sec;
let min = dt.min;
let hour = dt.hour;
let day = dt.day;
let month = dt.month;
let year = dt.year;
let ts = chrono::NaiveDateTime::new(
chrono::NaiveDate::from_ymd(year, month as u32, day as u32),
chrono::NaiveTime::from_hms(hour as u32, min as u32, sec as u32),
chrono::NaiveDate::from_ymd(year, month, day),
chrono::NaiveTime::from_hms(hour, min, sec),
);
let (zone_hour, zone_min) = if dt.dt_zone >= 0 {
(dt.dt_zone / 100, dt.dt_zone % 100)
let (zone_hour, zone_min) = if dt.zone >= 0 {
(dt.zone / 100, dt.zone % 100)
} else {
(-(-dt.dt_zone / 100), -(-dt.dt_zone % 100))
(-(-dt.zone / 100), -(-dt.zone % 100))
};
ts.timestamp() - (zone_hour * 3600 + zone_min * 60) as i64