truncateInterval truncates the input interval downward to the nearest interval quantity specified by the DurationField input. If precision is set for seconds, this will instead round at the second layer.
(d *duration.Duration, itm types.IntervalTypeMetadata)
| 3155 | // interval quantity specified by the DurationField input. |
| 3156 | // If precision is set for seconds, this will instead round at the second layer. |
| 3157 | func truncateInterval(d *duration.Duration, itm types.IntervalTypeMetadata) { |
| 3158 | switch itm.DurationField.DurationType { |
| 3159 | case types.IntervalDurationType_YEAR: |
| 3160 | d.Months = d.Months - d.Months%12 |
| 3161 | d.Days = 0 |
| 3162 | d.SetNanos(0) |
| 3163 | case types.IntervalDurationType_MONTH: |
| 3164 | d.Days = 0 |
| 3165 | d.SetNanos(0) |
| 3166 | case types.IntervalDurationType_DAY: |
| 3167 | d.SetNanos(0) |
| 3168 | case types.IntervalDurationType_HOUR: |
| 3169 | d.SetNanos(d.Nanos() - d.Nanos()%time.Hour.Nanoseconds()) |
| 3170 | case types.IntervalDurationType_MINUTE: |
| 3171 | d.SetNanos(d.Nanos() - d.Nanos()%time.Minute.Nanoseconds()) |
| 3172 | case types.IntervalDurationType_SECOND, types.IntervalDurationType_UNSET: |
| 3173 | if itm.PrecisionIsSet || itm.Precision > 0 { |
| 3174 | prec := TimeFamilyPrecisionToRoundDuration(itm.Precision) |
| 3175 | d.SetNanos(time.Duration(d.Nanos()).Round(prec).Nanoseconds()) |
| 3176 | } |
| 3177 | } |
| 3178 | } |
| 3179 | |
| 3180 | // ParseDIntervalWithTypeMetadata is like ParseDInterval, but it also takes a |
| 3181 | // types.IntervalTypeMetadata that both specifies the units for unitless, numeric intervals |
no test coverage detected
searching dependent graphs…