-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Date & Calendar extensions (#26)
- Loading branch information
Showing
11 changed files
with
101 additions
and
91 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
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/javatimefun/calendar/extensions/CalendarMutatingExtensions.kt
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,23 @@ | ||
package javatimefun.calendar.extensions | ||
|
||
import javatimefun.localdate.LocalDateUtil | ||
import javatimefun.localdatetime.LocalDateTimeUtil | ||
import javatimefun.localtime.LocalTimeUtil | ||
import java.time.* | ||
import java.util.Calendar | ||
|
||
/** | ||
* @param useSystemTimeZone If true, converts to time zone of the device, else leaves as is on calendar. | ||
* @return ZonedDateTime. | ||
*/ | ||
fun Calendar.toZonedDateTime(): ZonedDateTime = | ||
ZonedDateTime.ofInstant(this.toInstant(), ZoneId.of(this.timeZone.id)) | ||
|
||
fun Calendar.toLocalDateTime(): LocalDateTime = | ||
LocalDateTimeUtil.new(this.toInstant().toEpochMilli()) | ||
|
||
fun Calendar.toLocalDate(): LocalDate = | ||
LocalDateUtil.new(this.toInstant().toEpochMilli()) | ||
|
||
fun Calendar.toLocalTime(): LocalTime = | ||
LocalTimeUtil.new(this.toInstant().toEpochMilli()) |
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/javatimefun/date/extensions/DateMutatingExtensions.kt
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,36 @@ | ||
package javatimefun.date.extensions | ||
|
||
import javatimefun.localdate.LocalDateUtil | ||
import javatimefun.localdatetime.LocalDateTimeUtil | ||
import javatimefun.localtime.LocalTimeUtil | ||
import javatimefun.zoneddatetime.ZonedDateTimeUtil | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
import java.time.LocalTime | ||
import java.time.ZonedDateTime | ||
import java.util.Date | ||
|
||
/** | ||
* @param useSystemTimeZone If true, converts to time zone of the device, else leaves as UTC. | ||
* @return ZonedDateTime. | ||
*/ | ||
fun Date.toZonedDateTime(useSystemTimeZone: Boolean = true): ZonedDateTime = | ||
ZonedDateTimeUtil.new(this.toInstant().toEpochMilli(), useSystemTimeZone) | ||
|
||
/** | ||
* @return LocalDateTime. | ||
*/ | ||
fun Date.toLocalDateTime(): LocalDateTime = | ||
LocalDateTimeUtil.new(this.toInstant().toEpochMilli()) | ||
|
||
/** | ||
* @return LocalDate. | ||
*/ | ||
fun Date.toLocalDate(): LocalDate = | ||
LocalDateUtil.new(this.toInstant().toEpochMilli()) | ||
|
||
/** | ||
* @return LocalTime. | ||
*/ | ||
fun Date.toLocalTime(): LocalTime = | ||
LocalTimeUtil.new(this.toInstant().toEpochMilli()) |
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
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
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