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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
use derive_more::{Display, From, Into};
use core::{num::NonZeroU64, str::FromStr, time::Duration};
use crate::{
error::ParseHourError,
types::macros::*,
types::{Entry as GenericEntry, *},
utils::u64_digits,
};
/// A single subtitle entry in an SRT file.
pub type Entry<T> = GenericEntry<Header, T>;
/// The hour component (0–999) of a timestamp.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Display, Into)]
#[display("{}", self.as_str())]
#[repr(transparent)]
pub struct Hour(pub(crate) u16);
impl FromStr for Hour {
type Err = ParseHourError;
#[cfg_attr(not(tarpaulin), inline(always))]
fn from_str(s: &str) -> Result<Self, Self::Err> {
hour_from_str!(s)
}
}
impl Hour {
/// Create a new `Hour` with value 0.
///
/// ```rust
/// use fasrt::srt::Hour;
///
/// let hour = Hour::new();
/// assert_eq!(hour.as_str(), "00");
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn new() -> Self {
Self::with(0)
}
/// Create a new `Hour` from a `u16`.
///
/// # Panics
/// Panics if the value is greater than 999.
///
/// ```rust
/// use fasrt::srt::Hour;
///
/// let hour = Hour::with(5);
/// assert_eq!(hour.as_str(), "05");
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn with(value: u16) -> Self {
if value > 999 {
panic!("Hour value must be between 0-999");
}
Self(value)
}
/// Try to create a new `Hour` from a `u16`, returning `None` if the value is out of range.
///
/// ```rust
/// use fasrt::srt::Hour;
///
/// assert_eq!(Hour::try_with(500), Some(Hour::with(500)));
/// assert_eq!(Hour::try_with(1000), None);
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn try_with(value: u16) -> Option<Self> {
if value > 999 { None } else { Some(Self(value)) }
}
/// Returns the string representation of this `Hour`, zero-padded to 2 digits.
///
/// ```rust
/// use fasrt::srt::Hour;
///
/// let hour = Hour::with(5);
/// assert_eq!(hour.as_str(), "05");
///
/// let hour = Hour::with(123);
/// assert_eq!(hour.as_str(), "123");
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn as_str(&self) -> &'static str {
hour_to_str!(self.0)
}
}
/// A timestamp in an SRT file, with millisecond precision.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Display, From)]
#[display("{}:{}:{},{}", hours, minutes, seconds, millis)]
pub struct Timestamp {
/// Hours (0–999).
hours: Hour,
/// Milliseconds (0–999).
millis: Millisecond,
/// Minutes (0–59).
minutes: Minute,
/// Seconds (0–59).
seconds: Second,
}
impl Default for Timestamp {
/// ```rust
/// use fasrt::srt::Timestamp;
/// use fasrt::srt::Hour;
/// use fasrt::types::{Minute, Second, Millisecond};
///
/// let timestamp = Timestamp::default();
/// assert_eq!(timestamp.hours(), Hour::with(0));
/// assert_eq!(timestamp.minutes(), Minute::with(0));
/// assert_eq!(timestamp.seconds(), Second::with(0));
/// assert_eq!(timestamp.millis(), Millisecond::with(0));
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
fn default() -> Self {
Self::new()
}
}
impl Timestamp {
/// Create a new timestamp.
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn new() -> Self {
Self::from_hmsm(Hour(0), Minute(0), Second(0), Millisecond(0))
}
/// Create a new timestamp from hours, minutes, seconds, and milliseconds.
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn from_hmsm(
hours: Hour,
minutes: Minute,
seconds: Second,
millis: Millisecond,
) -> Self {
Self {
hours,
minutes,
seconds,
millis,
}
}
/// Returns the hours component of this timestamp.
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn hours(&self) -> Hour {
self.hours
}
/// Returns the minutes component of this timestamp.
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn minutes(&self) -> Minute {
self.minutes
}
/// Returns the seconds component of this timestamp.
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn seconds(&self) -> Second {
self.seconds
}
/// Returns the milliseconds component of this timestamp.
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn millis(&self) -> Millisecond {
self.millis
}
/// Build a new timestamp with the hours field set to the given value.
///
/// ```rust
/// use fasrt::srt::Timestamp;
/// use fasrt::srt::Hour;
///
/// let timestamp = Timestamp::default().with_hours(Hour::with(1));
/// assert_eq!(timestamp.hours(), Hour::with(1));
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn with_hours(mut self, hours: Hour) -> Self {
self.set_hours(hours);
self
}
/// Build a new timestamp with the minutes field set to the given value.
///
/// ```rust
/// use fasrt::srt::Timestamp;
/// use fasrt::types::Minute;
///
/// let timestamp = Timestamp::default().with_minutes(Minute::with(1));
/// assert_eq!(timestamp.minutes(), Minute::with(1));
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn with_minutes(mut self, minutes: Minute) -> Self {
self.set_minutes(minutes);
self
}
/// Build a new timestamp with the seconds field set to the given value.
///
/// ```rust
/// use fasrt::srt::Timestamp;
/// use fasrt::types::Second;
///
/// let timestamp = Timestamp::default().with_seconds(Second::with(1));
/// assert_eq!(timestamp.seconds(), Second::with(1));
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn with_seconds(mut self, seconds: Second) -> Self {
self.set_seconds(seconds);
self
}
/// Build a new timestamp with the millis field set to the given value.
///
/// ```rust
/// use fasrt::srt::Timestamp;
/// use fasrt::types::Millisecond;
///
/// let timestamp = Timestamp::default().with_millis(Millisecond::with(1));
/// assert_eq!(timestamp.millis(), Millisecond::with(1));
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn with_millis(mut self, millis: Millisecond) -> Self {
self.set_millis(millis);
self
}
/// Set the hours field of this timestamp.
///
/// ```rust
/// use fasrt::srt::Timestamp;
/// use fasrt::srt::Hour;
///
/// let mut timestamp = Timestamp::default();
/// timestamp.set_hours(Hour::with(1));
/// assert_eq!(timestamp.hours(), Hour::with(1));
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn set_hours(&mut self, hours: Hour) -> &mut Self {
self.hours = hours;
self
}
/// Set the minutes field of this timestamp.
///
/// ```rust
/// use fasrt::srt::Timestamp;
/// use fasrt::types::Minute;
///
/// let mut timestamp = Timestamp::default();
/// timestamp.set_minutes(Minute::with(1));
/// assert_eq!(timestamp.minutes(), Minute::with(1));
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn set_minutes(&mut self, minutes: Minute) -> &mut Self {
self.minutes = minutes;
self
}
/// Set the seconds field of this timestamp.
///
/// ```rust
/// use fasrt::srt::Timestamp;
/// use fasrt::types::Second;
///
/// let mut timestamp = Timestamp::default();
/// timestamp.set_seconds(Second::with(1));
/// assert_eq!(timestamp.seconds(), Second::with(1));
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn set_seconds(&mut self, seconds: Second) -> &mut Self {
self.seconds = seconds;
self
}
/// Set the millis field of this timestamp.
///
/// ```rust
/// use fasrt::srt::Timestamp;
/// use fasrt::types::Millisecond;
///
/// let mut timestamp = Timestamp::default();
/// timestamp.set_millis(Millisecond::with(1));
/// assert_eq!(timestamp.millis(), Millisecond::with(1));
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn set_millis(&mut self, millis: Millisecond) -> &mut Self {
self.millis = millis;
self
}
/// Set the hours, minutes, seconds, and milliseconds fields of this timestamp.
///
/// ```rust
/// use fasrt::srt::Timestamp;
/// use fasrt::srt::Hour;
/// use fasrt::types::{Minute, Second, Millisecond};
///
/// let mut timestamp = Timestamp::default();
/// timestamp.set_hmsm(Hour::with(1), Minute::with(2), Second::with(3), Millisecond::with(4));
/// assert_eq!(timestamp.hours(), Hour::with(1));
/// assert_eq!(timestamp.minutes(), Minute::with(2));
/// assert_eq!(timestamp.seconds(), Second::with(3));
/// assert_eq!(timestamp.millis(), Millisecond::with(4));
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn set_hmsm(
&mut self,
hours: Hour,
minutes: Minute,
seconds: Second,
millis: Millisecond,
) -> &mut Self {
self.hours = hours;
self.minutes = minutes;
self.seconds = seconds;
self.millis = millis;
self
}
/// Convert this timestamp to a `Duration`.
///
/// ```rust
/// use core::time::Duration;
/// use fasrt::srt::Timestamp;
/// use fasrt::srt::Hour;
/// use fasrt::types::{Minute, Second, Millisecond};
///
/// let timestamp = Timestamp::from_hmsm(Hour::with(1), Minute::with(2), Second::with(3), Millisecond::with(4));
/// let duration = timestamp.to_duration();
/// assert_eq!(duration, Duration::from_millis(1 * 3_600_000 + 2 * 60_000 + 3 * 1_000 + 4));
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn to_duration(&self) -> Duration {
let hours = self.hours.0 as u64;
let minutes = self.minutes.0 as u64;
let seconds = self.seconds.0 as u64;
let millis = self.millis.0 as u64;
Duration::from_millis(hours * 3_600_000 + minutes * 60_000 + seconds * 1_000 + millis)
}
/// Returns the encoded length of this timestamp.
///
/// ```rust
/// use fasrt::srt::Timestamp;
/// use fasrt::srt::Hour;
/// use fasrt::types::{Minute, Second, Millisecond};
///
/// let timestamp = Timestamp::from_hmsm(Hour::with(1), Minute::with(2), Second::with(3), Millisecond::with(4));
/// assert_eq!(timestamp.encoded_len(), 12);
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn encoded_len(&self) -> usize {
self.hours().as_str().len() + 1 // HH:
+ self.minutes().as_str().len() + 1 // MM:
+ self.seconds().as_str().len() + 1 // SS, or SS.
+ self.millis().as_str().len() // mmm
}
/// Format this timestamp to a SRT timestamp string.
///
/// ```rust
/// use fasrt::srt::Timestamp;
/// use fasrt::srt::Hour;
/// use fasrt::types::{Minute, Second, Millisecond};
///
/// let timestamp = Timestamp::from_hmsm(Hour::with(1), Minute::with(2), Second::with(3), Millisecond::with(4));
/// assert_eq!(timestamp.encode().as_str(), "01:02:03,004");
///
/// let timestamp = Timestamp::from_hmsm(Hour::with(122), Minute::with(34), Second::with(56), Millisecond::with(789));
/// assert_eq!(timestamp.encode().as_str(), "122:34:56,789");
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn encode(&self) -> Buffer<14> {
let mut buffer = Buffer::new();
buffer.write_str(self.hours().as_str());
buffer.write_str(":");
buffer.write_str(self.minutes().as_str());
buffer.write_str(":");
buffer.write_str(self.seconds().as_str());
buffer.write_str(",");
buffer.write_str(self.millis().as_str());
buffer
}
}
/// The header of a subtitle entry, containing the index and timestamps, but not the text.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Header {
index: Option<NonZeroU64>,
start: Timestamp,
end: Timestamp,
}
impl Header {
/// Create a new `Header` with the given index, start time, and end time.
///
/// ```rust
/// use fasrt::srt::{Header, Timestamp};
///
/// let header = Header::new(Timestamp::default(), Timestamp::default());
/// assert_eq!(header.index(), None);
/// assert_eq!(header.start(), Timestamp::default());
/// assert_eq!(header.end(), Timestamp::default());
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn new(start: Timestamp, end: Timestamp) -> Self {
Self {
index: None,
start,
end,
}
}
/// Returns the index of this subtitle header, or `None` if it was missing.
///
/// ```rust
/// use fasrt::srt::{Header, Timestamp};
///
/// let header = Header::new(Timestamp::default(), Timestamp::default());
/// assert_eq!(header.index(), None);
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn index(&self) -> Option<NonZeroU64> {
self.index
}
/// Sets the index of this subtitle header.
///
/// ```rust
/// use fasrt::srt::{Header, Timestamp};
/// use core::num::NonZeroU64;
///
/// let mut header = Header::new(Timestamp::default(), Timestamp::default());
/// header.set_index(NonZeroU64::new(1).unwrap());
/// assert_eq!(header.index(), NonZeroU64::new(1));
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn with_index(mut self, index: NonZeroU64) -> Self {
self.set_index(index);
self
}
/// Sets the index of this subtitle header.
///
/// ```rust
/// use fasrt::srt::{Header, Timestamp};
/// use core::num::NonZeroU64;
///
/// let mut header = Header::new(Timestamp::default(), Timestamp::default())
/// .maybe_index(Some(NonZeroU64::new(1).unwrap()));
/// assert_eq!(header.index(), NonZeroU64::new(1));
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn set_index(&mut self, index: NonZeroU64) -> &mut Self {
self.update_index(Some(index));
self
}
/// Sets the index of this subtitle header.
///
/// ```rust
/// use fasrt::srt::{Header, Timestamp};
///
/// let header = Header::new(Timestamp::default(), Timestamp::default()).maybe_index(None);
/// assert_eq!(header.index(), None);
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn maybe_index(mut self, index: Option<NonZeroU64>) -> Self {
self.update_index(index);
self
}
/// Sets the index of this subtitle header.
///
/// ```rust
/// use fasrt::srt::{Header, Timestamp};
///
/// let mut header = Header::new(Timestamp::default(), Timestamp::default());
/// header.update_index(None);
/// assert_eq!(header.index(), None);
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn update_index(&mut self, index: Option<NonZeroU64>) -> &mut Self {
self.index = index;
self
}
/// Returns the start time of this subtitle header.
///
/// ```rust
/// use fasrt::srt::{Header, Timestamp};
///
/// let header = Header::new(Timestamp::default(), Timestamp::default());
/// assert_eq!(header.start(), Timestamp::default());
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn start(&self) -> Timestamp {
self.start
}
/// Sets the start time of this subtitle header.
///
/// ```rust
/// use fasrt::{
/// srt::{Header, Hour, Timestamp},
/// types::{Minute, Second, Millisecond},
/// };
///
/// let header = Header::new(Timestamp::default(), Timestamp::default())
/// .with_start(Timestamp::from_hmsm(Hour::with(1), Minute::with(2), Second::with(3), Millisecond::with(4)));
/// assert_eq!(header.start(), Timestamp::from_hmsm(Hour::with(1), Minute::with(2), Second::with(3), Millisecond::with(4)));
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn with_start(mut self, start: Timestamp) -> Self {
self.set_start(start);
self
}
/// Sets the start time of this subtitle header.
///
/// ```rust
/// use fasrt::{
/// srt::{Header, Hour, Timestamp},
/// types::{Minute, Second, Millisecond},
/// };
///
/// let mut header = Header::new(Timestamp::default(), Timestamp::default());
/// header.set_start(Timestamp::from_hmsm(Hour::with(1), Minute::with(2), Second::with(3), Millisecond::with(4)));
/// assert_eq!(header.start(), Timestamp::from_hmsm(Hour::with(1), Minute::with(2), Second::with(3), Millisecond::with(4)));
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn set_start(&mut self, start: Timestamp) -> &mut Self {
self.start = start;
self
}
/// Returns the end time of this subtitle header.
///
/// ```rust
/// use fasrt::srt::{Header, Timestamp};
///
/// let header = Header::new(Timestamp::default(), Timestamp::default());
/// assert_eq!(header.end(), Timestamp::default());
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn end(&self) -> Timestamp {
self.end
}
/// Sets the end time of this subtitle header.
///
/// ```rust
/// use fasrt::{
/// srt::{Header, Hour, Timestamp},
/// types::{Minute, Second, Millisecond},
/// };
///
/// let header = Header::new(Timestamp::default(), Timestamp::default())
/// .with_end(Timestamp::from_hmsm(Hour::with(1), Minute::with(2), Second::with(3), Millisecond::with(4)));
/// assert_eq!(header.end(), Timestamp::from_hmsm(Hour::with(1), Minute::with(2), Second::with(3), Millisecond::with(4)));
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn with_end(mut self, end: Timestamp) -> Self {
self.set_end(end);
self
}
/// Sets the end time of this subtitle header.
///
/// ```rust
/// use fasrt::{
/// srt::{Header, Hour, Timestamp},
/// types::{Minute, Second, Millisecond},
/// };
///
/// let mut header = Header::new(Timestamp::default(), Timestamp::default());
/// header.set_end(Timestamp::from_hmsm(Hour::with(1), Minute::with(2), Second::with(3), Millisecond::with(4)));
/// assert_eq!(header.end(), Timestamp::from_hmsm(Hour::with(1), Minute::with(2), Second::with(3), Millisecond::with(4)));
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn set_end(&mut self, end: Timestamp) -> &mut Self {
self.end = end;
self
}
/// Returns the encoded length of this subtitle header.
///
/// ```rust
/// use fasrt::srt::{Header, Timestamp};
///
/// let header = Header::new(Timestamp::default(), Timestamp::default());
/// assert_eq!(header.encoded_len(), 30);
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn encoded_len(&self) -> usize {
let start_len = self.start.encoded_len();
let end_len = self.end.encoded_len();
match self.index {
Some(index) => {
u64_digits(index.get()) + 1 // index\n
+ start_len + 5 + end_len // HHH:MM:ss,mmm --> HHH:MM:ss,mmm
+ 1 // newline after header
}
None => start_len + 5 + end_len + 1, // HHH:MM:ss,mmm --> HHH:MM:ss,mmm\n
}
}
/// Format this timestamp to a SRT timestamp string.
///
/// ```rust
/// use fasrt::srt::{Header, Hour, Timestamp};
/// use core::num::NonZeroU64;
///
/// let header = Header::new(Timestamp::default(), Timestamp::default()).with_index(NonZeroU64::new(u64::MAX).unwrap());
/// let encoded_len = header.encoded_len();
/// let buf = header.encode();
/// assert_eq!(buf.len(), encoded_len);
/// assert_eq!(buf.as_str(), "18446744073709551615\n00:00:00,000 --> 00:00:00,000\n");
///
/// let header = Header::new(Timestamp::default().with_hours(Hour::with(122)), Timestamp::default().with_hours(Hour::with(123))).with_index(NonZeroU64::new(u64::MAX).unwrap());
/// let encoded_len = header.encoded_len();
/// let buf = header.encode();
/// assert_eq!(buf.len(), encoded_len);
/// assert_eq!(buf.as_str(), "18446744073709551615\n122:00:00,000 --> 123:00:00,000\n");
/// ```
#[cfg_attr(not(tarpaulin), inline(always))]
pub const fn encode(&self) -> Buffer<54> {
let mut buffer = Buffer::new();
if let Some(index) = self.index {
buffer.fmt_u64(index.get());
buffer.write_str("\n");
}
buffer.write_str(self.start.encode().as_str());
buffer.write_str(" --> ");
buffer.write_str(self.end.encode().as_str());
buffer.write_str("\n");
buffer
}
}
#[test]
#[should_panic]
fn hour_panic() {
let _ = Hour::with(1000);
}