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
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
//! Time and related data structures
//!
//! this module exports three different components of time:
//! [`SystemTime`], [`LocalDateTime`] and [`Duration`].
//!
//! [`SystemTime`]: ./struct.SystemTime.html
//! [`LocalDateTime`]: ./struct.LocalDateTime.html
//! [`Duration`]: ./struct.Duration.html

use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::{convert::TryFrom, fmt, str};
use time::OffsetDateTime;

/// time in seconds since [UNIX Epoch]
///
/// This type is meant to be easily converted between [`SystemTime`]
///
/// # Example
///
/// ```
/// # use jormungandr_lib::time::{SystemTime, SecondsSinceUnixEpoch};
///
/// let time = SystemTime::from(SecondsSinceUnixEpoch::MAX);
///
/// println!("max allowed time: {}", time);
/// // max allowed time: 4147-08-20T07:32:15+00:00
/// ```
///
/// [`SystemTime`]: ./struct.SystemTime.html
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
pub struct SecondsSinceUnixEpoch(pub(crate) u64);

/// time in seconds and nanoseconds since [UNIX Epoch]
///
/// The human readable formatting is [ISO8601] compliant.
///
/// # Example
///
/// ```
/// # use jormungandr_lib::time::SystemTime;
///
/// let time = SystemTime::now();
///
/// println!("now: {}", time);
/// // now: 2019-06-17T18:17:20.417032+00:00
/// ```
///
/// [ISO8601]: https://en.wikipedia.org/wiki/ISO_8601
/// [`LocalDateTime`]: ./struct.LocalDateTime.html
/// [UNIX Epoch]: https://en.wikipedia.org/wiki/Unix_time
///
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct SystemTime(std::time::SystemTime);

/// local date and time. While the [`SystemTime`] will give us a number of seconds
/// since [UNIX Epoch] this will take into account the locality of the caller, taking
/// into account daylight saving.
///
/// # Example
///
/// ```
/// # use jormungandr_lib::time::LocalDateTime;
///
/// let time = LocalDateTime::now();
///
/// println!("now: {}", time);
/// // now: Mon, 17 Jun 2019 20:19:29 +0200
/// ```
///
/// [`SystemTime`]: ./struct.SystemTime.html
/// [UNIX Epoch]: https://en.wikipedia.org/wiki/Unix_time
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct LocalDateTime(OffsetDateTime);

/// Length of time between 2 events.
///
/// # Example
///
/// ```
/// # use jormungandr_lib::time::Duration;
///
/// let duration = Duration::new(9289, 200000000);
///
/// println!("started: {}", duration);
/// // started: 2h 34m 49s 200ms
/// ```
///
///
/// [UNIX Epoch]: https://en.wikipedia.org/wiki/Unix_time
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Duration(std::time::Duration);

impl SecondsSinceUnixEpoch {
    /// maximum authorized Time in seconds since unix epoch
    ///
    /// This value will take you up to the year 4147.
    pub const MAX: Self = SecondsSinceUnixEpoch(0x000_000F_FFFF_FFFF);

    pub fn now() -> Self {
        SystemTime::now().into()
    }
}

impl SystemTime {
    /// get the current time in seconds since [UNIX Epoch]
    ///
    /// [UNIX Epoch]: https://en.wikipedia.org/wiki/Unix_time
    #[inline]
    pub fn now() -> Self {
        SystemTime(std::time::SystemTime::now())
    }

    pub fn duration_since(
        &self,
        earlier: SystemTime,
    ) -> Result<Duration, std::time::SystemTimeError> {
        self.0.duration_since(earlier.0).map(Duration)
    }
}

impl LocalDateTime {
    #[inline]
    pub fn now() -> Self {
        LocalDateTime(OffsetDateTime::now_local().expect("could not get local offset"))
    }
}

impl Duration {
    #[inline]
    pub fn new(secs: u64, nanos: u32) -> Self {
        Duration(std::time::Duration::new(secs, nanos))
    }

    pub fn as_secs(&self) -> u64 {
        self.0.as_secs()
    }

    pub fn as_secs_f64(&self) -> f64 {
        self.0.as_secs_f64()
    }

    pub fn as_millis(&self) -> u128 {
        self.0.as_millis()
    }

    pub fn as_micro(&self) -> u128 {
        self.0.as_micros()
    }

    pub fn as_nanos(&self) -> u128 {
        self.0.as_nanos()
    }

    pub fn from_millis(millis: u64) -> Self {
        Duration(std::time::Duration::from_millis(millis))
    }

    pub fn checked_add(self, rhs: Duration) -> Option<Duration> {
        self.0.checked_add(rhs.0).map(Duration)
    }

    pub fn checked_sub(self, rhs: Duration) -> Option<Duration> {
        self.0.checked_sub(rhs.0).map(Duration)
    }
}

/* --------------------- Default ------------------------------------------- */

impl Default for SecondsSinceUnixEpoch {
    fn default() -> SecondsSinceUnixEpoch {
        SecondsSinceUnixEpoch::now()
    }
}

/* --------------------- Display ------------------------------------------- */

impl fmt::Display for Duration {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        humantime::Duration::from(self.0).fmt(f)
    }
}

impl str::FromStr for Duration {
    type Err = humantime::DurationError;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let duration = humantime::parse_duration(s)?;
        Ok(Duration(duration))
    }
}

impl fmt::Display for SystemTime {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        // time-rs's format_into requires an implementor of std::io::Write, which fmt::Formatter is not
        let formatted = OffsetDateTime::from(self.0)
            .format(&time::format_description::well_known::Rfc3339)
            .map_err(|_| fmt::Error)?;
        write!(f, "{}", formatted)
    }
}

impl str::FromStr for SystemTime {
    type Err = time::error::Parse;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(Self(
            OffsetDateTime::parse(s, &time::format_description::well_known::Rfc3339)?.into(),
        ))
    }
}

impl fmt::Display for LocalDateTime {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        // time-rs's format_into requires an implementor of std::io::Write, which fmt::Formatter is not
        let formatted = self
            .0
            .format(&time::format_description::well_known::Rfc2822)
            .map_err(|_| fmt::Error)?;
        write!(f, "{}", formatted)
    }
}

impl str::FromStr for LocalDateTime {
    type Err = time::error::Parse;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(Self(OffsetDateTime::parse(
            s,
            &time::format_description::well_known::Rfc2822,
        )?))
    }
}

impl fmt::Display for SecondsSinceUnixEpoch {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        self.0.fmt(f)
    }
}

impl str::FromStr for SecondsSinceUnixEpoch {
    type Err = std::num::ParseIntError;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        s.parse().map(SecondsSinceUnixEpoch)
    }
}

/* --------------------- AsRef --------------------------------------------- */

impl AsRef<std::time::Duration> for Duration {
    fn as_ref(&self) -> &std::time::Duration {
        &self.0
    }
}

impl AsRef<std::time::SystemTime> for SystemTime {
    fn as_ref(&self) -> &std::time::SystemTime {
        &self.0
    }
}

impl AsRef<time::OffsetDateTime> for LocalDateTime {
    fn as_ref(&self) -> &time::OffsetDateTime {
        &self.0
    }
}

/* --------------------- Conversion ---------------------------------------- */

impl TryFrom<SystemTime> for LocalDateTime {
    type Error = std::time::SystemTimeError;
    fn try_from(system_time: SystemTime) -> Result<Self, Self::Error> {
        Ok(LocalDateTime(system_time.0.into()))
    }
}

impl From<std::time::SystemTime> for SystemTime {
    fn from(system_time: std::time::SystemTime) -> Self {
        SystemTime(system_time)
    }
}

impl From<SystemTime> for std::time::SystemTime {
    fn from(system_time: SystemTime) -> Self {
        system_time.0
    }
}

impl From<std::time::SystemTime> for SecondsSinceUnixEpoch {
    fn from(system_time: std::time::SystemTime) -> Self {
        system_time
            .duration_since(std::time::UNIX_EPOCH)
            // duration since UNIX EPOCH will never go beyond boundaries
            .map(|duration| duration.as_secs())
            .map(SecondsSinceUnixEpoch::from_secs)
            .unwrap()
    }
}

impl SystemTime {
    pub fn from_secs_since_epoch(secs: u64) -> Self {
        // here we can safely unwrap as we are adding from UNIX_EPOCH (0)
        // and SecondsSinceUnixEpoch is always a positive integer
        // and seconds will always be within bounds
        std::time::UNIX_EPOCH
            .checked_add(std::time::Duration::from_secs(secs))
            .unwrap()
            .into()
    }

    pub fn duration_since_epoch(self) -> Duration {
        Duration(self.0.duration_since(std::time::UNIX_EPOCH).unwrap())
    }
}

impl SecondsSinceUnixEpoch {
    pub fn from_secs(secs: u64) -> Self {
        SecondsSinceUnixEpoch(secs)
    }

    pub fn to_secs(self) -> u64 {
        self.0
    }
}

impl From<std::time::Duration> for Duration {
    fn from(duration: std::time::Duration) -> Self {
        Duration(duration)
    }
}

impl From<Duration> for std::time::Duration {
    fn from(Duration(duration): Duration) -> Self {
        duration
    }
}

impl From<SecondsSinceUnixEpoch> for SystemTime {
    fn from(seconds: SecondsSinceUnixEpoch) -> SystemTime {
        SystemTime::from_secs_since_epoch(seconds.0)
    }
}

impl From<SystemTime> for SecondsSinceUnixEpoch {
    fn from(system_time: SystemTime) -> SecondsSinceUnixEpoch {
        system_time.0.into()
    }
}

/* ------------------- Serde ----------------------------------------------- */

impl<'de> Deserialize<'de> for SecondsSinceUnixEpoch {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: Deserializer<'de>,
    {
        use serde::de::{self, Visitor};
        struct SecondsSinceUnixEpochVisitor;
        impl<'de> Visitor<'de> for SecondsSinceUnixEpochVisitor {
            type Value = SecondsSinceUnixEpoch;
            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
                write!(
                    formatter,
                    "seconds since unix epoch up to '{}' ({})",
                    SecondsSinceUnixEpoch::MAX,
                    SystemTime::from(SecondsSinceUnixEpoch::MAX),
                )
            }

            fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E>
            where
                E: de::Error,
            {
                let seconds = SecondsSinceUnixEpoch(v);

                if seconds > SecondsSinceUnixEpoch::MAX {
                    Err(E::custom("Time value is way too far in the future"))
                } else {
                    Ok(seconds)
                }
            }
        }
        deserializer.deserialize_u64(SecondsSinceUnixEpochVisitor)
    }
}

impl Serialize for SystemTime {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        if serializer.is_human_readable() {
            self.to_string().serialize(serializer)
        } else {
            self.0.serialize(serializer)
        }
    }
}

impl<'de> Deserialize<'de> for SystemTime {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: Deserializer<'de>,
    {
        use serde::de::{self, Visitor};
        struct SystemTimeVisitor;
        impl<'de> Visitor<'de> for SystemTimeVisitor {
            type Value = SystemTime;
            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
                formatter.write_str("system time in ISO8601 format")
            }

            fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
            where
                E: de::Error,
            {
                s.parse().map_err(E::custom)
            }
        }

        if deserializer.is_human_readable() {
            deserializer.deserialize_str(SystemTimeVisitor)
        } else {
            std::time::SystemTime::deserialize(deserializer).map(SystemTime)
        }
    }
}

impl Serialize for Duration {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        if serializer.is_human_readable() {
            self.to_string().serialize(serializer)
        } else {
            self.0.serialize(serializer)
        }
    }
}

impl<'de> Deserialize<'de> for Duration {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: Deserializer<'de>,
    {
        use serde::de::{self, Visitor};
        struct DurationVisitor;
        impl<'de> Visitor<'de> for DurationVisitor {
            type Value = Duration;
            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
                formatter.write_str("duration in the form of '10days 7h 2m 45s'")
            }

            fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
            where
                E: de::Error,
            {
                s.parse().map_err(E::custom)
            }
        }

        if deserializer.is_human_readable() {
            deserializer.deserialize_str(DurationVisitor)
        } else {
            std::time::Duration::deserialize(deserializer).map(Duration)
        }
    }
}

impl Serialize for LocalDateTime {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        if serializer.is_human_readable() {
            self.to_string().serialize(serializer)
        } else {
            unimplemented!("non human readable format not supported for LocalDateTime")
        }
    }
}

impl<'de> Deserialize<'de> for LocalDateTime {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: Deserializer<'de>,
    {
        use serde::de::{self, Visitor};
        struct LocalDateTimeVisitor;
        impl<'de> Visitor<'de> for LocalDateTimeVisitor {
            type Value = LocalDateTime;
            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
                formatter.write_str("local date and time, in RFC2822 format")
            }

            fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
            where
                E: de::Error,
            {
                s.parse().map_err(E::custom)
            }
        }

        assert!(
            deserializer.is_human_readable(),
            "LocalDateTime only supported for human readable format"
        );
        deserializer.deserialize_str(LocalDateTimeVisitor)
    }
}

#[cfg(test)]
mod test {
    use super::*;
    use ::time::macros::datetime;
    use quickcheck::{Arbitrary, Gen};
    use std::time;

    impl Arbitrary for Duration {
        fn arbitrary<G: Gen>(g: &mut G) -> Self {
            Duration::new(u64::arbitrary(g), u32::arbitrary(g))
        }
    }

    impl Arbitrary for SystemTime {
        fn arbitrary<G: Gen>(g: &mut G) -> Self {
            let secs = u64::arbitrary(g) % 0xFF_FFFF_FFFF;
            let nanos = u32::arbitrary(g) % 999_999_999;
            SystemTime(
                time::SystemTime::UNIX_EPOCH
                    .checked_add(time::Duration::new(secs, nanos))
                    .unwrap(),
            )
        }
    }

    impl Arbitrary for LocalDateTime {
        fn arbitrary<G: Gen>(g: &mut G) -> Self {
            const MAX: i64 = ::time::Date::MAX.midnight().assume_utc().unix_timestamp();
            let secs = i64::arbitrary(g) % MAX;
            Self(OffsetDateTime::from_unix_timestamp(secs).expect("invalid timestamp"))
        }
    }

    impl Arbitrary for SecondsSinceUnixEpoch {
        fn arbitrary<G: Gen>(g: &mut G) -> Self {
            SecondsSinceUnixEpoch(u64::arbitrary(g) % SecondsSinceUnixEpoch::MAX.0)
        }
    }

    quickcheck! {
        fn system_time_display_parse(time: SystemTime) -> bool {
            let s = time.to_string();
            let time_dec: SystemTime = s.parse().unwrap();

            time == time_dec
        }

        fn system_time_serde_human_readable_encode_decode(time: SystemTime) -> bool {
            let s = serde_yaml::to_string(&time).unwrap();
            let time_dec: SystemTime = serde_yaml::from_str(&s).unwrap();

            time == time_dec
        }

        fn system_time_serde_binary_readable_encode_decode(time: SystemTime) -> bool {
            let s = bincode::serialize(&time).unwrap();
            let time_dec: SystemTime = bincode::deserialize(&s).unwrap();

            time == time_dec
        }

        fn local_date_time_display_parse(time: LocalDateTime) -> bool {
            let s = time.to_string();
            let time_dec: LocalDateTime = s.parse().unwrap();

            dbg!(s);
            dbg!(&time_dec);

            time == time_dec
        }

        fn local_date_time_serde_human_readable_encode_decode(time: LocalDateTime) -> bool {
            let s = serde_yaml::to_string(&time).unwrap();
            let time_dec: LocalDateTime = serde_yaml::from_str(&s).unwrap();

            time == time_dec
        }

        fn duration_display_parse(duration: Duration) -> bool {
            let s = duration.to_string();
            let duration_dec: Duration = s.parse().unwrap();

            duration == duration_dec
        }

        fn duration_serde_human_readable_encode_decode(duration: Duration) -> bool {
            let s = serde_yaml::to_string(&duration).unwrap();
            let duration_dec: Duration = serde_yaml::from_str(&s).unwrap();

            duration == duration_dec
        }

        fn duration_serde_binary_readable_encode_decode(duration: Duration) -> bool {
            let s = bincode::serialize(&duration).unwrap();
            let duration_dec: Duration = bincode::deserialize(&s).unwrap();

            duration == duration_dec
        }

        fn seconds_since_unix_epoch_serde_human_readable_encode_decode(seconds: SecondsSinceUnixEpoch) -> bool {
            let s = serde_yaml::to_string(&seconds).unwrap();
            let seconds_dec: SecondsSinceUnixEpoch = serde_yaml::from_str(&s).unwrap();

            seconds == seconds_dec
        }

        fn seconds_since_unix_epoch_serde_binary_readable_encode_decode(seconds: SecondsSinceUnixEpoch) -> bool {
            let s = bincode::serialize(&seconds).unwrap();
            let seconds_dec: SecondsSinceUnixEpoch = bincode::deserialize(&s).unwrap();

            seconds == seconds_dec
        }
    }

    #[test]
    fn system_time_display_iso8601() {
        let epoch = SystemTime(time::UNIX_EPOCH);

        assert_eq!(epoch.to_string(), "1970-01-01T00:00:00Z")
    }

    #[test]
    fn system_time_serde_human_readable() {
        let epoch = SystemTime(time::UNIX_EPOCH);

        assert_eq!(
            serde_yaml::to_string(&epoch).unwrap(),
            "---\n\"1970-01-01T00:00:00Z\"\n"
        )
    }

    #[test]
    fn local_date_time_display_rfc_2822() {
        let local = LocalDateTime(datetime!(2017-08-17 11:59:42 +0));

        assert!(local.to_string().starts_with("Thu, 17 Aug 2017 "));
    }

    #[test]
    fn local_date_time_serde_human_readable() {
        let local = LocalDateTime(datetime!(2017-08-17 11:59:42 +0));

        assert!(serde_yaml::to_string(&local)
            .unwrap()
            .starts_with("---\n\"Thu, 17 Aug 2017 "))
    }

    #[test]
    fn duration_display_readable() {
        let duration = Duration(time::Duration::new(928_237, 1_129_000));

        assert_eq!(duration.to_string(), "10days 17h 50m 37s 1ms 129us")
    }

    #[test]
    fn duration_serde_human_readable() {
        let duration = Duration(time::Duration::new(928_237, 1_129_000));

        assert_eq!(
            serde_yaml::to_string(&duration).unwrap(),
            "---\n10days 17h 50m 37s 1ms 129us\n"
        )
    }

    #[test]
    fn check_conversions_seconds_since_epoch_between_system_time_boundaries() {
        let seconds_since_epoch = SecondsSinceUnixEpoch::MAX;

        let system_time = SystemTime::from(seconds_since_epoch);

        let seconds_since_epoch_2 = SecondsSinceUnixEpoch::from(system_time);

        assert_eq!(seconds_since_epoch, seconds_since_epoch_2);
    }

    #[test]
    fn seconds_since_unix_epoch_serde_human_readable() {
        let duration = SecondsSinceUnixEpoch(9_982_716);

        assert_eq!(serde_yaml::to_string(&duration).unwrap(), "---\n9982716\n")
    }

    #[test]
    #[should_panic]
    fn out_of_bound_seconds_since_unix_epoch_serde_human_readable_fail() {
        let invalid_yaml = format!("---\n{}\n", SecondsSinceUnixEpoch::MAX.0 + 1);

        let _: SecondsSinceUnixEpoch = serde_yaml::from_str(&invalid_yaml).unwrap();
    }
}