forked from tidepool-org/LoopAlgorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDate.swift
More file actions
27 lines (21 loc) · 689 Bytes
/
Date.swift
File metadata and controls
27 lines (21 loc) · 689 Bytes
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
//
// Date.swift
//
// Created by Nathan Racklyeft on 1/17/16.
// Copyright © 2016 Nathan Racklyeft. All rights reserved.
//
import Foundation
public extension Date {
func dateFlooredToTimeInterval(_ interval: TimeInterval) -> Date {
if interval == 0 {
return self
}
return Date(timeIntervalSinceReferenceDate: floor(self.timeIntervalSinceReferenceDate / interval) * interval)
}
func dateCeiledToTimeInterval(_ interval: TimeInterval) -> Date {
if interval == 0 {
return self
}
return Date(timeIntervalSinceReferenceDate: ceil(self.timeIntervalSinceReferenceDate / interval) * interval)
}
}