-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add more to Date, Calendar, GregorianCalendar
- Loading branch information
Showing
7 changed files
with
132 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 - Sebastian Ritter <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
import Foundation | ||
|
||
extension java.util.Calender { | ||
public enum DateComponents : Int { | ||
case YEAR = 1 | ||
case DAY_OF_WEEK = 7 | ||
case DAY_OF_MONTH = 8 | ||
case HOUR_OF_DAY = 11 | ||
case MINUTE = 12 | ||
case SECOND = 13 | ||
} | ||
|
||
public func setTime (from newDate: Foundation.Date) { | ||
let calendar = Foundation.Calendar(identifier: .gregorian) | ||
var components : Foundation.DateComponents | ||
if #available(macOS 14, *) /* .isLeapMonth */{ | ||
components = calendar.dateComponents([.year, .month, .day, .hour, .minute, .second, .weekdayOrdinal, .weekday, .weekOfYear, .weekOfMonth, .timeZone, .quarter, .nanosecond, .isLeapMonth, .era], from: newDate ) | ||
} else { | ||
components = calendar.dateComponents([.year, .month, .day, .hour, .minute, .second, .weekdayOrdinal, .weekday, .weekOfYear, .weekOfMonth, .timeZone, .quarter, .nanosecond, .era], from: newDate) | ||
} | ||
self.dateComponents = components | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 - Sebastian Ritter <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
import Foundation | ||
|
||
extension java.util { | ||
/// Abstract Java type | ||
/// | ||
open class Calender { | ||
internal var dateComponents : Foundation.DateComponents = Foundation.DateComponents() | ||
|
||
public init (){ | ||
let calendar = Foundation.Calendar(identifier: .gregorian) | ||
let now = Foundation.Date() | ||
var components : Foundation.DateComponents | ||
if #available(macOS 14, *) /* .isLeapMonth */{ | ||
components = calendar.dateComponents([.year, .month, .day, .hour, .minute, .second, .weekdayOrdinal, .weekday, .weekOfYear, .weekOfMonth, .timeZone, .quarter, .nanosecond, .isLeapMonth, .era], from:now) | ||
} else { | ||
components = calendar.dateComponents([.year, .month, .day, .hour, .minute, .second, .weekdayOrdinal, .weekday, .weekOfYear, .weekOfMonth, .timeZone, .quarter, .nanosecond, .era], from:now) | ||
} | ||
self.dateComponents = components | ||
} | ||
|
||
public static let SECOND = 13 | ||
public static let MINUTE = 12 | ||
public static let HOUR_OF_DAY = 11 | ||
public static let YEAR = 1 | ||
public static let DAY_OF_MONTH = 8 | ||
public static let DAY_OF_WEEK = 7 | ||
|
||
open func get (_ field : Int) throws -> Int { | ||
throw java.lang.Throwable.UnsupportedOperationException("Calendar is a abstract type, use subtypes like GregorianCalendar") | ||
} | ||
|
||
public func setTime (_ newDate :java.util.Date) { | ||
self.setTime(from: newDate.delegate) | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters