servo/components/style/values/computed/time.rs
author Bogdan Tara <btara@mozilla.com>
Wed, 10 Apr 2019 17:54:45 +0300
changeset 468773 e0edc59f9158d65e91a45cb6b1d96d75b5998da3
parent 468755 7da7a8bc596a97e823c5837bad136ceba5db7ac4
child 468776 79752758fc82bda5a89bd3a3860fc20aea10d72f
permissions -rw-r--r--
Backed out 5 changesets (bug 1542178) for for test_flexbox_flex_shorthand.html failures CLOSED TREE Backed out changeset 7fbaca51f682 (bug 1542178) Backed out changeset e5a602010961 (bug 1542178) Backed out changeset 152985a87c01 (bug 1542178) Backed out changeset 7da7a8bc596a (bug 1542178) Backed out changeset 0a7766ece186 (bug 1542178)

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

//! Computed time values.

use crate::values::CSSFloat;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};

/// A computed `<time>` value.
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, PartialOrd)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
pub struct Time {
    seconds: CSSFloat,
}

impl Time {
    /// Creates a time value from a seconds amount.
    pub fn from_seconds(seconds: CSSFloat) -> Self {
        Time { seconds: seconds }
    }

    /// Returns `0s`.
    pub fn zero() -> Self {
        Self::from_seconds(0.0)
    }

    /// Returns the amount of seconds this time represents.
    #[inline]
    pub fn seconds(&self) -> CSSFloat {
        self.seconds
    }
}

impl ToCss for Time {
    fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
    where
        W: Write,
    {
        self.seconds().to_css(dest)?;
        dest.write_str("s")
    }
}