@@ -3,21 +3,21 @@ package au.com.dius.pact.core.model.generators
3
3
import au.com.dius.pact.com.github.michaelbull.result.Err
4
4
import au.com.dius.pact.com.github.michaelbull.result.Ok
5
5
import au.com.dius.pact.com.github.michaelbull.result.Result
6
- import au.com.dius.pact.com.github.michaelbull.result.get
7
- import au.com.dius.pact.com.github.michaelbull.result.map
8
6
import au.com.dius.pact.com.github.michaelbull.result.mapError
9
7
import mu.KLogging
10
8
import java.lang.Integer.parseInt
11
9
import java.time.OffsetDateTime
12
- import java.time.temporal.ChronoUnit
13
10
14
11
object DateTimeExpression : KLogging() {
15
12
fun executeExpression (base : OffsetDateTime , expression : String? ): Result <OffsetDateTime , String > {
16
13
return if (! expression.isNullOrEmpty()) {
17
14
val split = expression.split(" @" , limit = 2 )
18
15
if (split.size > 1 ) {
19
16
val datePart = DateExpression .executeDateExpression(base, split[0 ])
20
- val timePart = TimeExpression .executeTimeExpression(base.toOffsetTime(), split[1 ])
17
+ val timePart = if (datePart is Ok <OffsetDateTime >)
18
+ TimeExpression .executeTimeExpression(datePart.value, split[1 ])
19
+ else
20
+ TimeExpression .executeTimeExpression(base, split[1 ])
21
21
when {
22
22
datePart is Err <String > && timePart is Err <String > -> datePart.mapError { " $it , " +
23
23
Regex (" 1:(\\ d+)" ).replace(timePart.error) { mr ->
@@ -32,7 +32,7 @@ object DateTimeExpression : KLogging() {
32
32
" 1:${pos + split[0 ].length + 1 } "
33
33
}
34
34
}
35
- else -> datePart.map { it.truncatedTo( ChronoUnit . DAYS ). with ( timePart.get() !! .toLocalTime()) }
35
+ else -> timePart
36
36
}
37
37
} else {
38
38
DateExpression .executeDateExpression(base, split[0 ])
0 commit comments