32 lines
709 B
Swift
32 lines
709 B
Swift
//
|
|
// NullifyDate.swift
|
|
// AutoCatCore
|
|
//
|
|
// Created by Selim Mustafaev on 30.11.2024.
|
|
// Copyright © 2024 Selim Mustafaev. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
@propertyWrapper
|
|
public struct NullifyDate: Sendable, Equatable, Hashable {
|
|
|
|
public var wrappedValue: Date? {
|
|
didSet {
|
|
wrappedValue = nullifyTime(of: wrappedValue)
|
|
}
|
|
}
|
|
|
|
public init(wrappedValue: Date?) {
|
|
self.wrappedValue = nullifyTime(of: wrappedValue)
|
|
}
|
|
|
|
func nullifyTime(of date: Date?) -> Date? {
|
|
guard let date else {
|
|
return nil
|
|
}
|
|
|
|
return Calendar.current.date(bySettingHour: 0, minute: 0, second: 0, of: date)
|
|
}
|
|
}
|