pub struct FormattedEvent {
pub id: i32,
pub start: String,
pub end: String,
pub duration: String,
}Expand description
Represents a formatted time-based event for display purposes.
This structure holds string representations of event properties, making it suitable for direct use with table-rendering libraries and data export systems. All time values are pre-formatted for consistent display.
ยงDesign Rationale
Rather than storing raw time values and formatting them at display time, this structure pre-formats all values to strings. This approach provides:
- Performance: No repeated formatting calculations
- Consistency: All instances use identical formatting
- Simplicity: Direct use in templates and display systems
- Serialization: Easy JSON/CSV export without custom formatters
ยงUsage Context
This structure is primarily used for:
- Console table display of work intervals
- CSV export of time-based data
- JSON serialization for API responses
- Report generation and data visualization
ยงField Descriptions
id: Sequential number for ordering and referencestart: Formatted start time (typically โHH:MMโ)end: Formatted end time (typically โHH:MMโ)duration: Formatted duration (typically โHH:MMโ)
ยงExamples
use kasl::libs::formatter::FormattedEvent;
// Work interval representation
let interval = FormattedEvent {
id: 1,
start: "09:00".to_string(),
end: "12:00".to_string(),
duration: "03:00".to_string(),
};
// Pause representation
let pause = FormattedEvent {
id: 2,
start: "12:00".to_string(),
end: "12:30".to_string(),
duration: "00:30".to_string(),
};Fieldsยง
ยงid: i32The sequential identifier of the event.
Used for ordering events chronologically and providing reference numbers in display tables. Typically starts from 1 and increments for each event in a sequence.
start: StringThe formatted start time (e.g., โ09:00โ, โ14:30โ).
Represents when the event began, typically formatted as โHH:MMโ in 24-hour format. For work intervals, this is when work started. For pauses, this is when the break began.
end: StringThe formatted end time (e.g., โ17:00โ, โ15:15โ).
Represents when the event ended, typically formatted as โHH:MMโ in 24-hour format. May be โ-โ or empty if the event is ongoing or has no defined end time.
duration: StringThe formatted duration (e.g., โ08:00โ, โ00:45โ).
Represents the total length of the event, formatted as โHH:MMโ. This is calculated from the difference between start and end times. May be โโ:โโ if the duration cannot be determined.
Trait Implementationsยง
Sourceยงimpl Clone for FormattedEvent
impl Clone for FormattedEvent
Sourceยงfn clone(&self) -> FormattedEvent
fn clone(&self) -> FormattedEvent
1.0.0 (const: unstable) ยท Sourceยงfn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more