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