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
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
use glib::translate::*;
use glib::StaticType;
use num_integer::div_rem;
use std::io::{self, prelude::*};
use std::time::Duration;
use std::{cmp, convert, fmt, str};
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Debug, Default)]
pub struct ClockTime(pub(crate) u64);
impl ClockTime {
pub const SECOND: ClockTime = ClockTime(1_000_000_000);
pub const MSECOND: ClockTime = ClockTime(1_000_000);
pub const USECOND: ClockTime = ClockTime(1_000);
pub const NSECOND: ClockTime = ClockTime(1);
pub const fn hours(self) -> u64 {
self.0 / Self::SECOND.0 / 60 / 60
}
pub const fn minutes(self) -> u64 {
self.0 / Self::SECOND.0 / 60
}
pub const fn seconds(self) -> u64 {
self.0 / Self::SECOND.0
}
pub const fn mseconds(self) -> u64 {
self.0 / Self::MSECOND.0
}
pub const fn useconds(self) -> u64 {
self.0 / Self::USECOND.0
}
pub const fn nseconds(self) -> u64 {
self.0
}
pub const fn from_seconds(seconds: u64) -> Self {
skip_assert_initialized!();
ClockTime(seconds * Self::SECOND.0)
}
pub const fn from_mseconds(mseconds: u64) -> Self {
skip_assert_initialized!();
ClockTime(mseconds * Self::MSECOND.0)
}
pub const fn from_useconds(useconds: u64) -> Self {
skip_assert_initialized!();
ClockTime(useconds * Self::USECOND.0)
}
pub const fn from_nseconds(nseconds: u64) -> Self {
skip_assert_initialized!();
ClockTime(nseconds * Self::NSECOND.0)
}
}
macro_rules! option_glib_newtype_from_to {
($type_:ident, $none_value:expr) => {
#[doc(hidden)]
impl IntoGlib for $type_ {
type GlibType = u64;
fn into_glib(self) -> u64 {
self.0
}
}
#[doc(hidden)]
impl OptionIntoGlib for $type_ {
const GLIB_NONE: u64 = $none_value;
}
#[doc(hidden)]
impl TryFromGlib<u64> for $type_ {
type Error = GlibNoneError;
#[inline]
unsafe fn try_from_glib(val: u64) -> Result<Self, GlibNoneError> {
skip_assert_initialized!();
if val == $none_value {
return Err(GlibNoneError);
}
Ok($type_(val))
}
}
};
}
option_glib_newtype_from_to!(ClockTime, ffi::GST_CLOCK_TIME_NONE);
impl glib::value::ValueType for ClockTime {
type Type = Self;
}
pub struct ClockTimeValueTypeOrNoneChecker<T>(std::marker::PhantomData<T>);
unsafe impl<T: StaticType> glib::value::ValueTypeChecker for ClockTimeValueTypeOrNoneChecker<T> {
type Error = glib::value::ValueTypeMismatchOrNoneError;
fn check(value: &glib::Value) -> Result<(), Self::Error> {
skip_assert_initialized!();
glib::value::GenericValueTypeChecker::<T>::check(value)?;
let gct = unsafe { glib::gobject_ffi::g_value_get_uint64(value.to_glib_none().0) };
if gct == ffi::GST_CLOCK_TIME_NONE {
return Err(glib::value::ValueTypeMismatchOrNoneError::UnexpectedNone);
}
Ok(())
}
}
unsafe impl<'a> glib::value::FromValue<'a> for ClockTime {
type Checker = ClockTimeValueTypeOrNoneChecker<Self>;
unsafe fn from_value(value: &glib::Value) -> ClockTime {
skip_assert_initialized!();
ClockTime(glib::gobject_ffi::g_value_get_uint64(
value.to_glib_none().0,
))
}
}
impl glib::value::ToValue for ClockTime {
fn to_value(&self) -> glib::Value {
let mut value = glib::Value::for_value_type::<ClockTime>();
let gct = self.into_glib();
if gct == ffi::GST_CLOCK_TIME_NONE {
crate::gst_warning!(
crate::CAT_RUST,
"converting a defined `ClockTime` with value `ffi::GST_CLOCK_TIME_NONE` to `Value`, this is probably not what you wanted.",
);
}
unsafe { glib::gobject_ffi::g_value_set_uint64(value.to_glib_none_mut().0, gct) }
value
}
fn value_type(&self) -> glib::Type {
Self::static_type()
}
}
impl glib::value::ToValueOptional for ClockTime {
fn to_value_optional(opt: Option<&Self>) -> glib::Value {
skip_assert_initialized!();
let mut value = glib::Value::for_value_type::<ClockTime>();
let inner = opt.map(|inner| inner.0).unwrap_or(ffi::GST_CLOCK_TIME_NONE);
unsafe { glib::gobject_ffi::g_value_set_uint64(value.to_glib_none_mut().0, inner) };
value
}
}
#[doc(hidden)]
impl glib::StaticType for ClockTime {
fn static_type() -> glib::Type {
<u64 as glib::StaticType>::static_type()
}
}
#[derive(Debug)]
pub struct DurationError;
impl fmt::Display for DurationError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "out of range conversion from Duration attempted")
}
}
impl std::error::Error for DurationError {}
impl convert::TryFrom<Duration> for ClockTime {
type Error = DurationError;
fn try_from(d: Duration) -> Result<Self, Self::Error> {
skip_assert_initialized!();
let nanos = d.as_nanos();
if nanos >= std::u64::MAX as u128 {
return Err(DurationError);
}
Ok(ClockTime::from_nseconds(nanos as u64))
}
}
impl convert::From<ClockTime> for Duration {
fn from(t: ClockTime) -> Self {
skip_assert_initialized!();
Duration::from_nanos(t.nseconds())
}
}
macro_rules! impl_common_ops_for_newtype_u64(
($name:ident) => {
impl $name {
pub const ZERO: Self = Self(0);
pub const NONE: Option<Self> = None;
pub const fn is_zero(self) -> bool {
self.0 == Self::ZERO.0
}
#[must_use = "this returns the result of the operation, without modifying the original"]
#[inline]
#[allow(clippy::manual_map)]
pub const fn checked_add(self, rhs: Self) -> Option<Self> {
match self.0.checked_add(rhs.0) {
Some(res) => Some(Self(res)),
None => None,
}
}
#[must_use = "this returns the result of the operation, without modifying the original"]
#[inline]
pub const fn saturating_add(self, rhs: Self) -> Self {
Self(self.0.saturating_add(rhs.0))
}
#[must_use = "this returns the result of the operation, without modifying the original"]
#[inline]
pub const fn wrapping_add(self, rhs: Self) -> Self {
Self(self.0.wrapping_add(rhs.0))
}
#[must_use = "this returns the result of the operation, without modifying the original"]
#[inline]
#[allow(clippy::manual_map)]
pub const fn checked_sub(self, rhs: Self) -> Option<Self> {
match self.0.checked_sub(rhs.0) {
Some(res) => Some(Self(res)),
None => None,
}
}
#[must_use = "this returns the result of the operation, without modifying the original"]
#[inline]
pub const fn saturating_sub(self, rhs: Self) -> Self {
Self(self.0.saturating_sub(rhs.0))
}
#[must_use = "this returns the result of the operation, without modifying the original"]
#[inline]
pub const fn wrapping_sub(self, rhs: Self) -> Self {
Self(self.0.wrapping_sub(rhs.0))
}
}
};
);
impl_common_ops_for_newtype_u64!(ClockTime);
enum Sign {
Undefined,
NonNegative,
#[allow(dead_code)]
Negative,
}
fn pad_clocktime(f: &mut fmt::Formatter<'_>, sign: Sign, buf: &str) -> fmt::Result {
skip_assert_initialized!();
use self::Sign::*;
use std::fmt::{Alignment, Write};
let sign_aware_zero_pad = f.sign_aware_zero_pad();
let fill_char = match sign {
Undefined if sign_aware_zero_pad => '-',
_ if sign_aware_zero_pad => '0',
_ => f.fill(),
};
let sign_plus = f.sign_plus();
let sign_char = match sign {
Undefined if sign_plus => Some(fill_char),
NonNegative if sign_plus => Some('+'),
Negative => Some('-'),
_ => None,
};
let width = buf.len() + sign_char.map_or(0, |_| 1);
let padding = f.width().unwrap_or(0).saturating_sub(width);
let align = f.align().unwrap_or(Alignment::Right);
let (pre_padding, zero_padding, post_padding) = match align {
_ if sign_aware_zero_pad => (0, padding, 0),
Alignment::Left => (0, 0, padding),
Alignment::Right => (padding, 0, 0),
Alignment::Center => (padding / 2, 0, (padding + 1) / 2),
};
for _ in 0..pre_padding {
f.write_char(fill_char)?;
}
if let Some(c) = sign_char {
f.write_char(c)?;
}
for _ in 0..zero_padding {
f.write_char(fill_char)?;
}
f.write_str(buf)?;
for _ in 0..post_padding {
f.write_char(fill_char)?;
}
Ok(())
}
fn write_clocktime<W: io::Write>(
mut writer: W,
clocktime: Option<ClockTime>,
precision: usize,
) -> io::Result<()> {
skip_assert_initialized!();
let precision = cmp::min(9, precision);
if let Some(ns) = clocktime.map(ClockTime::nseconds) {
let (s, ns) = div_rem(ns, 1_000_000_000);
let (m, s) = div_rem(s, 60);
let (h, m) = div_rem(m, 60);
write!(writer, "{}:{:02}:{:02}", h, m, s)?;
if precision > 0 {
let mut buf = [0u8; 9];
write!(&mut buf[..], "{:09}", ns).unwrap();
let buf_str = str::from_utf8(&buf[..]).unwrap();
write!(writer, ".{:.p$}", buf_str, p = precision)?;
}
} else {
write!(writer, "--:--:--")?;
if precision > 0 {
write!(writer, ".{:->p$}", "", p = precision)?;
}
}
Ok(())
}
fn fmt_opt_clock_time(ct: Option<ClockTime>, f: &mut fmt::Formatter) -> fmt::Result {
skip_assert_initialized!();
let precision = f.precision().unwrap_or(9);
const MAX_SIZE: usize = "5124095:34:33.709551614".len();
let mut buf = [0u8; MAX_SIZE];
let mut cursor = io::Cursor::new(&mut buf[..]);
write_clocktime(&mut cursor, ct, precision).unwrap();
let pos = cursor.position() as usize;
let buf_str = str::from_utf8(&buf[..pos]).unwrap();
let sign = if ct.is_some() {
Sign::NonNegative
} else {
Sign::Undefined
};
pad_clocktime(f, sign, buf_str)
}
impl fmt::Display for ClockTime {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt_opt_clock_time(Some(*self), f)
}
}
#[derive(Debug)]
pub struct DisplayableOptClockTime(Option<ClockTime>);
impl fmt::Display for DisplayableOptClockTime {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt_opt_clock_time(self.0, f)
}
}
impl crate::utils::Displayable for Option<ClockTime> {
type DisplayImpl = DisplayableOptClockTime;
fn display(self) -> DisplayableOptClockTime {
DisplayableOptClockTime(self)
}
}
impl crate::utils::Displayable for ClockTime {
type DisplayImpl = ClockTime;
fn display(self) -> ClockTime {
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn opt_time_clock() {
let ct_1 = ClockTime(1);
let opt_ct_none: Option<ClockTime> = None;
assert_eq!(ct_1.into_glib(), 1);
assert_eq!(Some(ct_1).into_glib(), 1);
assert_eq!(opt_ct_none.into_glib(), ffi::GST_CLOCK_TIME_NONE);
let ct_1_from: ClockTime = unsafe { try_from_glib(1u64) }.unwrap();
assert_eq!(ct_1_from, ct_1);
let opt_ct_some: Option<ClockTime> = unsafe { from_glib(1u64) };
assert_eq!(opt_ct_some, Some(ct_1));
let opt_ct_none: Option<ClockTime> = unsafe { from_glib(ffi::GST_CLOCK_TIME_NONE) };
assert_eq!(opt_ct_none, None);
}
#[test]
#[allow(clippy::eq_op, clippy::op_ref)]
fn ops() {
let ct_10 = 10 * ClockTime::MSECOND;
let ct_20 = 20 * ClockTime::MSECOND;
let ct_30 = 30 * ClockTime::MSECOND;
assert_eq!(ct_10 + ct_20, ct_30);
assert_eq!(ct_10 + &ct_20, ct_30);
assert_eq!(&ct_10 + &ct_20, ct_30);
assert_eq!(ct_30 - ct_20, ct_10);
assert_eq!(ct_30 - ct_30, ClockTime::ZERO);
assert_eq!(ct_10 * 3, ct_30);
assert_eq!(3 * ct_10, ct_30);
assert_eq!(3 * &ct_10, ct_30);
assert_eq!(ct_30.nseconds(), 30_000_000);
}
#[test]
fn checked_ops() {
let ct_1 = ClockTime::from_nseconds(1);
let ct_2 = ClockTime::from_nseconds(2);
let ct_max = ClockTime::from_nseconds(std::u64::MAX);
assert_eq!(ct_1.checked_add(ct_1), Some(ct_2));
assert_eq!(ct_1.checked_add(ct_1), Some(ct_2));
assert!(ct_max.checked_add(ct_1).is_none());
assert_eq!(ct_2.checked_sub(ct_1), Some(ct_1));
assert_eq!(ct_2.checked_sub(ct_1), Some(ct_1));
assert!(ct_1.checked_sub(ct_2).is_none());
}
#[test]
fn saturating_ops() {
let ct_1 = ClockTime::from_nseconds(1);
let ct_2 = ClockTime::from_nseconds(2);
let ct_3 = ClockTime::from_nseconds(3);
let ct_max = ClockTime::from_nseconds(std::u64::MAX);
assert_eq!(ct_1.saturating_add(ct_2), ct_3);
assert_eq!(ct_1.saturating_add(ct_2), ct_3);
assert_eq!(ct_max.saturating_add(ct_1), ct_max);
assert_eq!(ct_3.saturating_sub(ct_2), ct_1);
assert_eq!(ct_3.saturating_sub(ct_2), ct_1);
assert!(ct_1.saturating_sub(ct_2).is_zero());
}
#[test]
fn wrapping_ops() {
let ct_1 = ClockTime::NSECOND;
let ct_2 = 2 * ClockTime::NSECOND;
let ct_3 = 3 * ClockTime::NSECOND;
let ct_max = ClockTime::from_nseconds(std::u64::MAX);
assert_eq!(ct_1.wrapping_add(ct_2), ct_3);
assert_eq!(ct_1.wrapping_add(ct_2), ct_3);
assert_eq!(ct_max.wrapping_add(ct_1), ClockTime::ZERO);
assert_eq!(ct_3.wrapping_sub(ct_2), ct_1);
assert_eq!(ct_3.wrapping_sub(ct_2), ct_1);
assert_eq!(ct_1.wrapping_sub(ct_2), ct_max);
}
#[test]
fn comp() {
let ct_0 = ClockTime::ZERO;
let ct_2 = 2 * ClockTime::NSECOND;
let ct_3 = 3 * ClockTime::NSECOND;
let opt_ct_none: Option<ClockTime> = None;
assert!(ct_0 < ct_2);
assert!(Some(ct_0) < Some(ct_2));
assert!(ct_2 < ct_3);
assert!(Some(ct_2) < Some(ct_3));
assert!(ct_0 < ct_3);
assert!(Some(ct_0) < Some(ct_3));
assert!(ct_3 > ct_2);
assert!(Some(ct_3) > Some(ct_2));
assert!(ct_2 > ct_0);
assert!(Some(ct_2) > Some(ct_0));
assert!(ct_3 > ct_0);
assert!(Some(ct_3) > Some(ct_0));
assert_eq!(opt_ct_none < None, false);
assert_eq!(opt_ct_none > None, false);
assert_eq!(Some(ct_0) < opt_ct_none, false);
}
#[test]
fn display() {
let none = Option::<ClockTime>::None;
let some = Some(45_834_908_569_837 * ClockTime::NSECOND);
let lots = ClockTime::from_nseconds(std::u64::MAX - 1);
assert_eq!(format!("{:.0}", DisplayableOptClockTime(none)), "--:--:--");
assert_eq!(
format!("{:.3}", DisplayableOptClockTime(none)),
"--:--:--.---"
);
assert_eq!(
format!("{}", DisplayableOptClockTime(none)),
"--:--:--.---------"
);
assert_eq!(format!("{:.0}", DisplayableOptClockTime(some)), "12:43:54");
assert_eq!(
format!("{:.3}", DisplayableOptClockTime(some)),
"12:43:54.908"
);
assert_eq!(
format!("{}", DisplayableOptClockTime(some)),
"12:43:54.908569837"
);
assert_eq!(format!("{:.0}", lots), "5124095:34:33");
assert_eq!(format!("{:.3}", lots), "5124095:34:33.709");
assert_eq!(format!("{}", lots), "5124095:34:33.709551614");
assert_eq!(
format!("{:.10}", DisplayableOptClockTime(none)),
"--:--:--.---------"
);
assert_eq!(
format!("{:.10}", DisplayableOptClockTime(some)),
"12:43:54.908569837"
);
assert_eq!(format!("{:.10}", lots), "5124095:34:33.709551614");
assert_eq!(format!("{:4.0}", DisplayableOptClockTime(none)), "--:--:--");
assert_eq!(
format!("{:4.3}", DisplayableOptClockTime(none)),
"--:--:--.---"
);
assert_eq!(
format!("{:4}", DisplayableOptClockTime(none)),
"--:--:--.---------"
);
assert_eq!(format!("{:4.0}", DisplayableOptClockTime(some)), "12:43:54");
assert_eq!(
format!("{:4.3}", DisplayableOptClockTime(some)),
"12:43:54.908"
);
assert_eq!(
format!("{:4}", DisplayableOptClockTime(some)),
"12:43:54.908569837"
);
assert_eq!(format!("{:4.0}", lots), "5124095:34:33");
assert_eq!(format!("{:4.3}", lots), "5124095:34:33.709");
assert_eq!(format!("{:4}", lots), "5124095:34:33.709551614");
assert_eq!(
format!("{:>9.0}", DisplayableOptClockTime(none)),
" --:--:--"
);
assert_eq!(
format!("{:<9.0}", DisplayableOptClockTime(none)),
"--:--:-- "
);
assert_eq!(
format!("{:^10.0}", DisplayableOptClockTime(none)),
" --:--:-- "
);
assert_eq!(
format!("{:>13.3}", DisplayableOptClockTime(none)),
" --:--:--.---"
);
assert_eq!(
format!("{:<13.3}", DisplayableOptClockTime(none)),
"--:--:--.--- "
);
assert_eq!(
format!("{:^14.3}", DisplayableOptClockTime(none)),
" --:--:--.--- "
);
assert_eq!(
format!("{:>19}", DisplayableOptClockTime(none)),
" --:--:--.---------"
);
assert_eq!(
format!("{:<19}", DisplayableOptClockTime(none)),
"--:--:--.--------- "
);
assert_eq!(
format!("{:^20}", DisplayableOptClockTime(none)),
" --:--:--.--------- "
);
assert_eq!(
format!("{:>9.0}", DisplayableOptClockTime(some)),
" 12:43:54"
);
assert_eq!(
format!("{:<9.0}", DisplayableOptClockTime(some)),
"12:43:54 "
);
assert_eq!(
format!("{:^10.0}", DisplayableOptClockTime(some)),
" 12:43:54 "
);
assert_eq!(
format!("{:>13.3}", DisplayableOptClockTime(some)),
" 12:43:54.908"
);
assert_eq!(
format!("{:<13.3}", DisplayableOptClockTime(some)),
"12:43:54.908 "
);
assert_eq!(
format!("{:^14.3}", DisplayableOptClockTime(some)),
" 12:43:54.908 "
);
assert_eq!(
format!("{:>19}", DisplayableOptClockTime(some)),
" 12:43:54.908569837"
);
assert_eq!(
format!("{:<19}", DisplayableOptClockTime(some)),
"12:43:54.908569837 "
);
assert_eq!(
format!("{:^20}", DisplayableOptClockTime(some)),
" 12:43:54.908569837 "
);
assert_eq!(format!("{:>14.0}", lots), " 5124095:34:33");
assert_eq!(format!("{:<14.0}", lots), "5124095:34:33 ");
assert_eq!(format!("{:^15.0}", lots), " 5124095:34:33 ");
assert_eq!(format!("{:>18.3}", lots), " 5124095:34:33.709");
assert_eq!(format!("{:<18.3}", lots), "5124095:34:33.709 ");
assert_eq!(format!("{:^19.3}", lots), " 5124095:34:33.709 ");
assert_eq!(format!("{:>24}", lots), " 5124095:34:33.709551614");
assert_eq!(format!("{:<24}", lots), "5124095:34:33.709551614 ");
assert_eq!(format!("{:^25}", lots), " 5124095:34:33.709551614 ");
assert_eq!(
format!("{:+11.0}", DisplayableOptClockTime(none)),
" --:--:--"
);
assert_eq!(
format!("{:011.0}", DisplayableOptClockTime(none)),
"-----:--:--"
);
assert_eq!(
format!("{:+011.0}", DisplayableOptClockTime(none)),
"-----:--:--"
);
assert_eq!(
format!("{:+15.3}", DisplayableOptClockTime(none)),
" --:--:--.---"
);
assert_eq!(
format!("{:015.3}", DisplayableOptClockTime(none)),
"-----:--:--.---"
);
assert_eq!(
format!("{:+015.3}", DisplayableOptClockTime(none)),
"-----:--:--.---"
);
assert_eq!(
format!("{:+21}", DisplayableOptClockTime(none)),
" --:--:--.---------"
);
assert_eq!(
format!("{:021}", DisplayableOptClockTime(none)),
"-----:--:--.---------"
);
assert_eq!(
format!("{:+021}", DisplayableOptClockTime(none)),
"-----:--:--.---------"
);
assert_eq!(
format!("{:+11.0}", DisplayableOptClockTime(some)),
" +12:43:54"
);
assert_eq!(
format!("{:011.0}", DisplayableOptClockTime(some)),
"00012:43:54"
);
assert_eq!(
format!("{:+011.0}", DisplayableOptClockTime(some)),
"+0012:43:54"
);
assert_eq!(
format!("{:+15.3}", DisplayableOptClockTime(some)),
" +12:43:54.908"
);
assert_eq!(
format!("{:015.3}", DisplayableOptClockTime(some)),
"00012:43:54.908"
);
assert_eq!(
format!("{:+015.3}", DisplayableOptClockTime(some)),
"+0012:43:54.908"
);
assert_eq!(
format!("{:+21}", DisplayableOptClockTime(some)),
" +12:43:54.908569837"
);
assert_eq!(
format!("{:021}", DisplayableOptClockTime(some)),
"00012:43:54.908569837"
);
assert_eq!(
format!("{:+021}", DisplayableOptClockTime(some)),
"+0012:43:54.908569837"
);
assert_eq!(format!("{:+16.0}", lots), " +5124095:34:33");
assert_eq!(format!("{:016.0}", lots), "0005124095:34:33");
assert_eq!(format!("{:+016.0}", lots), "+005124095:34:33");
assert_eq!(format!("{:+20.3}", lots), " +5124095:34:33.709");
assert_eq!(format!("{:020.3}", lots), "0005124095:34:33.709");
assert_eq!(format!("{:+020.3}", lots), "+005124095:34:33.709");
assert_eq!(format!("{:+26}", lots), " +5124095:34:33.709551614");
assert_eq!(format!("{:026}", lots), "0005124095:34:33.709551614");
assert_eq!(format!("{:+026}", lots), "+005124095:34:33.709551614");
}
}