Skip to content

Commit a4db593

Browse files
author
mahdibohloul
committed
add convertLocalDateTimeToInstant method to TimeOperator, bump version to 0.9.4 in README and build.gradle.kts
1 parent fcdd86c commit a4db593

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ and formatting tools to accelerate development and maintain consistency across p
7171
<dependency>
7272
<groupId>box.tapsi.libs</groupId>
7373
<artifactId>utilities-starter</artifactId>
74-
<version>0.9.3</version>
74+
<version>0.9.4</version>
7575
</dependency>
7676
```
7777

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ plugins {
1010
}
1111

1212
group = "box.tapsi.libs"
13-
version = "0.9.3"
13+
version = "0.9.4"
1414
description = "utilities-starter"
1515

1616
repositories {

src/main/kotlin/box/tapsi/libs/utilities/time/TimeOperator.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java.time.DayOfWeek
44
import java.time.Duration
55
import java.time.Instant
66
import java.time.LocalDate
7+
import java.time.LocalDateTime
78
import java.time.LocalTime
89
import java.util.concurrent.TimeUnit
910

@@ -103,6 +104,18 @@ interface TimeOperator {
103104
*/
104105
fun convertLocalDateToInstant(localDate: LocalDate, timezone: SupportedTimezone = SupportedTimezone.Tehran): Instant
105106

107+
/**
108+
* Converts a LocalDateTime to an Instant using the provided timezone.
109+
*
110+
* @param localDateTime the LocalDateTime object to be converted.
111+
* @param timezone the timezone to be used for the conversion. Defaults to SupportedTimezone.Tehran.
112+
* @return the corresponding Instant representation of the provided LocalDateTime in the specified timezone.
113+
*/
114+
fun convertLocalDateTimeToInstant(
115+
localDateTime: LocalDateTime,
116+
timezone: SupportedTimezone = SupportedTimezone.Tehran,
117+
): Instant
118+
106119
/**
107120
* Retrieves the current local date based on the specified timezone.
108121
*

src/main/kotlin/box/tapsi/libs/utilities/time/TimeOperatorImpl.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java.time.DayOfWeek
44
import java.time.Duration
55
import java.time.Instant
66
import java.time.LocalDate
7+
import java.time.LocalDateTime
78
import java.time.LocalTime
89
import java.util.concurrent.TimeUnit
910

@@ -52,6 +53,11 @@ class TimeOperatorImpl : TimeOperator {
5253
timezone: SupportedTimezone,
5354
): Instant = localDate.atStartOfDay(timezone.asZoneId()).toInstant()
5455

56+
override fun convertLocalDateTimeToInstant(
57+
localDateTime: LocalDateTime,
58+
timezone: SupportedTimezone,
59+
): Instant = localDateTime.atZone(timezone.asZoneId()).toInstant()
60+
5561
override fun getCurrentLocalDate(timezone: SupportedTimezone): LocalDate = LocalDate.now(timezone.asZoneId())
5662

5763
override fun getCurrentDayOfWeek(timezone: SupportedTimezone): DayOfWeek = getCurrentLocalDate(timezone).dayOfWeek

0 commit comments

Comments
 (0)