Skip to content

Commit

Permalink
Removed TIMESTAMP_FORMAT (#242)
Browse files Browse the repository at this point in the history
## Summary of changes

Removed the constant `TIMESTAMP_FORMAT` from nexus-writer, and replaced
its usage with `to_rfc3339()`.

## Instruction for review/testing

Ensure changes to code are as described above.
  • Loading branch information
Modularius authored Sep 2, 2024
1 parent 20984f8 commit bde39f7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::nexus::{
hdf5_file::{add_attribute_to, add_new_group_to, create_resizable_dataset},
nexus_class as NX, NexusSettings, TIMESTAMP_FORMAT,
nexus_class as NX, NexusSettings,
};
use chrono::{DateTime, Duration, Utc};
use hdf5::{types::VarLenUnicode, Dataset, Group};
Expand Down Expand Up @@ -145,11 +145,7 @@ impl EventRun {
debug!("Offset found");
timestamp - offset
} else {
add_attribute_to(
&self.event_time_zero,
"offset",
&timestamp.format(TIMESTAMP_FORMAT).to_string(),
)?;
add_attribute_to(&self.event_time_zero, "offset", &timestamp.to_rfc3339())?;
self.offset = Some(timestamp);
debug!("New offset set");
Duration::zero()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use supermusr_streaming_types::{
};
use tracing::{debug, trace};

use crate::nexus::{hdf5_file::hdf5_writer::add_attribute_to, TIMESTAMP_FORMAT};
use crate::nexus::hdf5_file::hdf5_writer::add_attribute_to;

pub(super) type Slice1D = SliceInfo<[SliceInfoElem; 1], Dim<[usize; 1]>, Dim<[usize; 1]>>;

Expand Down Expand Up @@ -71,9 +71,7 @@ fn write_generic_logdata_slice_to_dataset<T: H5Type>(
impl<'a> TimeSeriesDataSource<'a> for f144_LogData<'a> {
#[tracing::instrument(skip(self))]
fn write_initial_timestamp(&self, target: &Dataset) -> anyhow::Result<()> {
let time = DateTime::<Utc>::from_timestamp_nanos(self.timestamp())
.format(TIMESTAMP_FORMAT)
.to_string();
let time = DateTime::<Utc>::from_timestamp_nanos(self.timestamp()).to_rfc3339();
add_attribute_to(target, "Start", &time)?;
add_attribute_to(target, "Units", "second")?;
Ok(())
Expand Down Expand Up @@ -185,9 +183,7 @@ where
impl<'a> TimeSeriesDataSource<'a> for se00_SampleEnvironmentData<'a> {
#[tracing::instrument(skip(self))]
fn write_initial_timestamp(&self, target: &Dataset) -> anyhow::Result<()> {
let time = DateTime::<Utc>::from_timestamp_nanos(self.packet_timestamp())
.format(TIMESTAMP_FORMAT)
.to_string();
let time = DateTime::<Utc>::from_timestamp_nanos(self.packet_timestamp()).to_rfc3339();
add_attribute_to(target, "Start", &time)?;
add_attribute_to(target, "Units", "second")?;
Ok(())
Expand Down
1 change: 0 additions & 1 deletion nexus-writer/src/nexus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub(crate) use engine::{NexusEngine, NexusSettings};
pub(crate) use run::Run;
pub(crate) use run_parameters::RunParameters;

pub(crate) const TIMESTAMP_FORMAT: &str = "%Y-%m-%dT%H:%M:%S%.f%z";
pub(crate) const DATETIME_FORMAT: &str = "%Y-%m-%dT%H:%M:%S%z";

pub(crate) mod nexus_class {
Expand Down

0 comments on commit bde39f7

Please sign in to comment.