1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//! Pause data management and formatting utilities.
//!
//! Provides the core data structures and formatting functionality for handling
//! break periods detected by the activity monitor.
//!
//! ## Features
//!
//! - **Data Modeling**: Represents pause periods with precise timing information
//! - **Display Formatting**: Converts raw pause data into human-readable formats
//! - **Collection Processing**: Batch operations on pause collections
//! - **Report Integration**: Provides data structures suitable for reporting systems
//!
//! ## Usage
//!
//! ```rust,no_run
//! # fn f() -> Result<(), chrono::ParseError> {
//! use kasl::libs::pause::Pause;
//! use chrono::{NaiveDateTime, Duration};
//!
//! let pause = Pause::detected(
//! 1,
//! NaiveDateTime::parse_from_str("2025-08-11 09:15:00", "%Y-%m-%d %H:%M:%S")?,
//! Some(NaiveDateTime::parse_from_str("2025-08-11 09:30:00", "%Y-%m-%d %H:%M:%S")?),
//! Some(Duration::minutes(15)),
//! );
//! # Ok(())
//! # }
//! ```
use ;
/// Represents a single pause period with complete timing information.
///
/// This structure models a break period detected by the activity monitor,
/// containing all necessary information for analysis, reporting, and display.
/// It handles both active (ongoing) and completed pause periods gracefully.
///
/// ## Field Semantics
///
/// - **`id`**: Unique database identifier for pause tracking and updates
/// - **`start`**: Precise timestamp when inactivity threshold was reached
/// - **`end`**: Completion timestamp (None for ongoing pauses)
/// - **`duration`**: Calculated break duration (None for ongoing pauses)
///
/// ## State Handling
///
/// The structure supports two primary states:
///
/// ### Completed Pause
/// - All fields populated with meaningful values
/// - `end` contains actual completion timestamp
/// - `duration` contains calculated break duration
/// - Ready for reporting and analysis
///
/// ### Ongoing Pause (Active)
/// - `start` field contains pause initiation time
/// - `end` field is None (pause still in progress)
/// - `duration` field is None (cannot calculate until completion)
/// - Can be displayed with special formatting for active state
///
/// ## Duration Calculation
///
/// Durations are calculated and stored at the database level for consistency:
/// - **Precision**: Calculated to the second for accurate reporting
/// - **Storage**: Stored as seconds in database, converted to Duration for display
/// - **Consistency**: All duration calculations use same algorithm
/// - **Timezone**: Uses local time for user-friendly display
///
/// ## Display Considerations
///
/// The structure is designed for easy formatting:
/// - Timestamps use standard format suitable for parsing
/// - Duration is compatible with `chrono::Duration` formatting utilities
/// - None values are handled gracefully in display formatting
/// - Supports both detailed and summary display modes