Skip to content
This repository has been archived by the owner on Mar 3, 2025. It is now read-only.

Commit

Permalink
correctly use time zone
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop22 committed Oct 3, 2024
1 parent 60c3877 commit a8eb2ef
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ pub struct TariffArgs {
#[arg(short = 't', long)]
tariff: Option<PathBuf>,
/// Timezone for evaluating any local times contained in the tariff structure.
#[arg(short = 'z', long, default_value = "Europe/Amsterdam")]
timezone: Tz,
#[arg(short = 'z', long, alias = "tz")]
timezone: Option<Tz>,
/// The OCPI version that should be used for the input structures.
///
/// If the input consists of version 2.1.1 structures they will be converted to 2.2.1
Expand Down Expand Up @@ -130,6 +130,10 @@ impl TariffArgs {
pricer = pricer.with_tariffs([tariff]);
};

if let Some(time_zone) = self.timezone {
pricer = pricer.with_time_zone(time_zone);
}

let report = pricer.build_report().map_err(Error::Internal)?;

Ok((report, cdr, tariff))
Expand Down Expand Up @@ -238,13 +242,13 @@ impl Validate {

table.row(&[
"Total Time Cost (Excl.)".into(),
to_string_or_default(report.total_time_cost.map(|p| p.excl_vat)),
to_string_or_default(report.total_time_cost.map(|p| p.with_scale().excl_vat)),
to_string_or_default(cdr.total_time_cost.map(|p| p.excl_vat)),
]);

table.row(&[
"Total Time Cost (Incl.)".into(),
to_string_or_default(report.total_time_cost.and_then(|p| p.incl_vat)),
to_string_or_default(report.total_time_cost.and_then(|p| p.with_scale().incl_vat)),
to_string_or_default(cdr.total_time_cost.and_then(|p| p.incl_vat)),
]);

Expand Down Expand Up @@ -345,9 +349,11 @@ impl Analyze {
style("Analyzing").green().bold(),
style(self.args.cdr_name()).blue(),
style(self.args.tariff_name()).blue(),
style(self.args.timezone).blue(),
style(&report.time_zone).blue(),
);

let time_zone: Tz = report.time_zone.parse().expect("invalid time zone");

let mut table = Table::new();

table.header(&[
Expand All @@ -360,7 +366,7 @@ impl Analyze {
]);

for period in report.periods.iter() {
let start_time = period.start_date_time.with_timezone(&self.args.timezone);
let start_time = period.start_date_time.with_timezone(&time_zone);
let dim = &period.dimensions;

table.row(&[
Expand Down

0 comments on commit a8eb2ef

Please sign in to comment.