Skip to content

Commit

Permalink
Javafy needed Instant implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
bastie committed Oct 29, 2023
1 parent c56ab1b commit 0cd0a05
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
24 changes: 24 additions & 0 deletions Sources/JavApi/time/Instant+AnyDate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* SPDX-FileCopyrightText: 2023 - Sebastian Ritter <[email protected]>
* SPDX-License-Identifier: MIT
*/

// This Instant extension encapsulate the compatibility layer for AnyDate users in respect of the AnyDate project
extension java.time.Instant {

@available(*, deprecated, renamed: "EPOCH", message: "this implementation is for compatibility")
public static var epoch: java.time.Instant { return java.time.Instant.EPOCH}

@available(*, deprecated, renamed: "MIN", message: "this implementation is for compatibility")
public static var min: java.time.Instant { return java.time.Instant.MIN }

@available(*, deprecated, renamed: "MAX", message: "this implementation is for compatibility")
public static var max: java.time.Instant { return java.time.Instant.MAX }

// AnyDate compatible
@available(*, deprecated, renamed: "plusSeconds", message: "this implementation is for compatibility")
public func plus(second: Int64) -> java.time.Instant {
return self.plusSeconds(second)
}

}
6 changes: 3 additions & 3 deletions Sources/JavApi/time/Instant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ extension java.time {
public func plus(component: Component, newValue: Int64) -> Instant {
switch component {
case .second:
return self.plus(second: newValue)
return self.plusSeconds(newValue)

case .nanosecond:
return self.plus(nano: newValue)
Expand All @@ -228,7 +228,7 @@ extension java.time {
///
/// - Parameters second: The amount of the second field to add to the result.
/// - Results: An Instant based on this instant with the specified amount added.
public func plus(second: Int64) -> Instant {
public func plusSeconds (_ secondsToAdd : Int64) -> Instant {
return Instant(
epochSecond: self.internalSecond + second,
nano: Int64(self.internalNano)
Expand Down Expand Up @@ -291,7 +291,7 @@ extension java.time {
/// - Parameters second: The amount of the second field to subtract to the result.
/// - Results: An Instant based on this instant with the specified amount subtracted.
public func minus(second: Int64) -> Instant {
return self.plus(second: -second)
return self.plusSeconds( -second)
}

/// Returns a copy of this instant with the specified duration in milliseconds subtracted.
Expand Down

0 comments on commit 0cd0a05

Please sign in to comment.