Scoop API

scoop:scoop.std:0.1.0

src/datetime/date_time_period.scoop

Selected production source · src/datetime/date_time_period.scoop

1package scoop.datetime
3import scoop.time.Duration
5/**
6 * A calendar DatePeriod followed by a fixed elapsed Duration. Applying it to a local date-time
7 * applies the date component first.
8 */
9public struct DateTimePeriod(val date: DatePeriod = DatePeriod(), val time: Duration = Duration.ZERO)
10 : Equals<DateTimePeriod>, Hash {
11 /**
12 * Compares the stored value components for equality.
13 */
14 public override operator fun equals(other: DateTimePeriod): Boolean = date == other.date && time == other.time
15 /**
16 * Computes a hash consistent with component equality.
17 */
18 public override fun hash(): Long = date.hash() * 31L + time.hash()
20 /**
21 * Value construction and serialization helpers.
22 */
23 public companion object : ValueEncoder<DateTimePeriod>, ValueDecoder<DateTimePeriod> {
24 /**
25 * Encodes the named components as keyed fields without normalizing the period.
26 */
27 public override fun encode(value: DateTimePeriod, encoder: Encoder) {
28 val fields = encoder.keyed()
29 DatePeriod.encode(value.date, fields.field("date"))
30 Duration.encode(value.time, fields.field("time"))
31 fields.end()
32 }
33 /**
34 * Decodes the required named components and reconstructs the period.
35 */
36 public override fun decode(decoder: Decoder): DateTimePeriod {
37 val fields = decoder.keyed()
38 val date = DatePeriod.decode(fields.required("date"))
39 val time = Duration.decode(fields.required("time"))
40 fields.end()
41 return DateTimePeriod(date, time)
42 }
43 }