Skip to content

Commit

Permalink
Date format
Browse files Browse the repository at this point in the history
  • Loading branch information
wtetsu committed May 6, 2022
1 parent 5a60bd1 commit 6378ce5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/epo/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,23 @@ pub struct ParseSettings {
pub date_formats_23: Vec<String>,
}

const DEFAULT_DATE_FORMAT: &str = "%Y-%m-%dT%H:%M:%S";
const DEFAULT_DATE_FORMAT_WITH_TZ: &str = "%Y-%m-%dT%H:%M:%S%z";

pub fn to_datestr_from_ndt(dt: NaiveDateTime) -> String {
dt.format(DEFAULT_DATE_FORMAT).to_string()
}

pub fn to_datestr(epoch_sec: i64, offset_sec: i32) -> String {
let dt = Utc.timestamp(epoch_sec, 0).with_timezone(&FixedOffset::east(offset_sec));

dt.format("%Y-%m-%dT%H:%M:%S%z").to_string()
dt.format(DEFAULT_DATE_FORMAT_WITH_TZ).to_string()
}

pub fn to_datestr_with_tz(epoch_sec: i64, timezone: &str) -> String {
let tz: Tz = timezone.parse().unwrap();
let dt = tz.timestamp(epoch_sec, 0);
dt.format("%Y-%m-%dT%H:%M:%S%z").to_string()
dt.format(DEFAULT_DATE_FORMAT_WITH_TZ).to_string()
}

pub fn parse_datestr_with_offset(datestr: &str, parse_settings: &ParseSettings) -> Result<EpochInfo, String> {
Expand Down
2 changes: 1 addition & 1 deletion src/epo/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn to_string_rows_from_dates(date_infos: &Vec<date::DateInfo>, timezones: &V
let mut rows: Vec<Vec<String>> = vec![];

for date in date_infos {
let mut row: Vec<String> = vec![date.datestr.to_string()];
let mut row: Vec<String> = vec![date::to_datestr_from_ndt(date.date_time)];
for t in timezones {
match t {
Zone::Offset(offset_sec) => {
Expand Down

0 comments on commit 6378ce5

Please sign in to comment.