TimeFormat

org.abh80.nf.core.time.TimeFormat
See theTimeFormat companion object
class TimeFormat(var seconds: Long, var attoseconds: Long) extends Comparable[TimeFormat], Serializable

Represents a time format with second and attosecond precision.

This class allows representing time values with a high degree of precision, using seconds and attoseconds (10^-18 seconds) as the units. It provides functionalities for basic arithmetic operations, comparisons, and conversions to and from other time units.

Value parameters

attoseconds

The number of attoseconds. Can be positive, negative, or zero. Must be in the range (-10^18, 10^18).

seconds

The number of seconds. Can be positive, negative, or zero.

Attributes

Throws
IllegalArgumentException

if attoseconds is outside the allowed range. Example usage:

 val time1 = new TimeFormat(1, 500000000000000000L) // 1.5 seconds
 val time2 = new TimeFormat(0, 750000000000000000L) // 0.75 seconds
 val sum = time1 + time2 // 2.25 seconds
 val difference = time1 - time2 // 0.75 seconds
 println(s"Sum: $sum")
 println(s"Difference: $difference")
Companion
object
Graph
Supertypes
trait Serializable
trait Comparable[TimeFormat]
class Object
trait Matchable
class Any
Known subtypes
class AbsoluteTime

Members list

Value members

Constructors

def this(tf: TimeFormat)

Copy constructor that creates a new TimeFormat instance from an existing one.

Copy constructor that creates a new TimeFormat instance from an existing one.

Value parameters

tf

The TimeFormat instance to copy

Attributes

Concrete methods

def *(scalar: Long): TimeFormat
Implicitly added by BinOp

Multiplies the time value by a scalar.

Multiplies the time value by a scalar.

Value parameters

scalar

The non-negative scalar value to multiply by

Attributes

Returns

A new TimeFormat instance representing the product

Throws
IllegalArgumentException

if scalar is negative

def +(second: TimeFormat): TimeFormat
Implicitly added by BinOp

Adds two TimeFormat instances.

Adds two TimeFormat instances.

Value parameters

second

The TimeFormat instance to add

Attributes

Returns

A new TimeFormat instance representing the sum

def -(second: TimeFormat): TimeFormat
Implicitly added by BinOp

Subtracts one TimeFormat instance from another.

Subtracts one TimeFormat instance from another.

Value parameters

second

The TimeFormat instance to subtract

Attributes

Returns

A new TimeFormat instance representing the difference

def /(scalar: Long): TimeFormat
Implicitly added by BinOp

Divides the time value by a scalar.

Divides the time value by a scalar.

Value parameters

scalar

The positive scalar value to divide by

Attributes

Returns

A new TimeFormat instance representing the quotient

Throws
IllegalArgumentException

if scalar is not positive

override def compareTo(o: TimeFormat): Int

Compares this TimeFormat instance with another TimeFormat instance.

Compares this TimeFormat instance with another TimeFormat instance.

Value parameters

o

The TimeFormat instance to compare with

Attributes

Returns

An integer value: - Negative if this instance is less than the other - Zero if they are equal - Positive if this instance is greater than the other

Definition Classes
Comparable
override def equals(obj: Any): Boolean

Compares the receiver object (this) with the argument object (that) for equivalence.

Compares the receiver object (this) with the argument object (that) for equivalence.

Any implementation of this method should be an equivalence relation:

  • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances x, y, and z of type Any if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode to ensure that objects which are "equal" (o1.equals(o2) returns true) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)).

Value parameters

that

the object to compare against this object for equality.

Attributes

Returns

true if the receiver object is equivalent to the argument; false otherwise.

Definition Classes
Any
def getAttoSeconds: Long

Gets the attoseconds component of the time value.

Gets the attoseconds component of the time value.

Attributes

Returns

The number of attoseconds

def getRoundedFormat(precision: Int): TimeFormat
def getSeconds: Long

Gets the seconds component of the time value.

Gets the seconds component of the time value.

Attributes

Returns

The number of seconds

override def hashCode(): Int

Calculates a hash code value for the object.

Calculates a hash code value for the object.

The default hashing algorithm is platform dependent.

Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

Attributes

Returns

the hash code value for this object.

Definition Classes
Any
def isZero: Boolean

Checks if this TimeFormat represents zero time (both seconds and attoseconds are 0).

Checks if this TimeFormat represents zero time (both seconds and attoseconds are 0).

Attributes

Returns

true if the time value is zero, false otherwise

Creates a new TimeFormat instance with the negated values of seconds and attoseconds.

Creates a new TimeFormat instance with the negated values of seconds and attoseconds.

Attributes

Returns

A new TimeFormat instance with negated values

def toDouble: Double

Converts current time format to double, "seconds[.]attoseconds"

Converts current time format to double, "seconds[.]attoseconds"

Attributes

Returns

a double value

override def toString: String

Returns a string representation of the time format in the form "seconds.attoseconds" where attoseconds is padded with leading zeros to 18 digits.

Returns a string representation of the time format in the form "seconds.attoseconds" where attoseconds is padded with leading zeros to 18 digits.

Attributes

Returns

A string representation of the time value

Definition Classes
Any