Skip to content

Commit

Permalink
Merge pull request #562 from smeup/feature/LS24003282/missing-duratio…
Browse files Browse the repository at this point in the history
…n-codes

Feature/ls24003282/missing duration codes
  • Loading branch information
lanarimarco authored Jul 11, 2024
2 parents 54df2e3 + 566122c commit 61323ee
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 11 deletions.
22 changes: 11 additions & 11 deletions rpgJavaInterpreter-core/src/main/antlr/RpgLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -373,21 +373,21 @@ SPLAT_LOCK: '*'[lL][oO][cC][kK];
SPLAT_PROGRAM: '*'[pP][rR][oO][gG][rR][aA][mM];
SPLAT_EXTDESC: '*'[eE][xX][tT][dD][eE][sS][cC];
//Durations
SPLAT_D: '*'{getLastTokenType() == COLON}? [dD];
SPLAT_H: '*'{getLastTokenType() == COLON}? [hH];
SPLAT_HOURS: '*'{getLastTokenType() == COLON}? [hH][oO][uU][rR][sS];
SPLAT_YEARS: SPLAT_YEAR[sS]{getLastTokenType() == COLON}?;
SPLAT_MONTHS: SPLAT_MONTH[sS];
SPLAT_DAYS: SPLAT_DAY[sS]{getLastTokenType() == COLON}?;
SPLAT_M: '*'{getLastTokenType() == COLON}? [mM];
SPLAT_HOURS: '*'{getLastTokenType() == COLON}? [hH][oO][uU][rR][sS];
SPLAT_MINUTES: '*'{getLastTokenType() == COLON}? [mM][iI][nN][uU][tT][eE][sS];
SPLAT_MONTHS: SPLAT_MONTH[sS];
SPLAT_MN: '*'{getLastTokenType() == COLON}? [mM][nN]; //Minutes
SPLAT_MS: '*'{getLastTokenType() == COLON}? [mM][sS]; //Minutes
SPLAT_MSECONDS: '*'{getLastTokenType() == COLON}? [mM][sS][eE][cC][oO][nN][dD][sS];
SPLAT_S: '*'{getLastTokenType() == COLON}? [sS];
SPLAT_SECONDS: '*'{getLastTokenType() == COLON}? [sS][eE][cC][oO][nN][dD][sS];
SPLAT_Y: '*'{getLastTokenType() == COLON}? [yY];
SPLAT_YEARS: SPLAT_YEAR[sS]{getLastTokenType() == COLON}?;
SPLAT_MSECONDS: '*'{getLastTokenType() == COLON}? [mM][sS][eE][cC][oO][nN][dD][sS];

SPLAT_Y: '*'{getLastTokenType() == COLON}? [yY];
SPLAT_D: '*'{getLastTokenType() == COLON}? [dD];
SPLAT_H: '*'{getLastTokenType() == COLON}? [hH];
SPLAT_MN: '*'{getLastTokenType() == COLON}? [mM][nN]; // Minutes
SPLAT_MS: '*'{getLastTokenType() == COLON}? [mM][sS]; // Microseconds
SPLAT_M: '*'{getLastTokenType() == COLON}? [mM]; // Months
SPLAT_S: '*'{getLastTokenType() == COLON}? [sS];

// Reserved Words
UDATE : [uU] [dD] [aA] [tT] [eE] ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ internal fun RpgParser.Bif_diffContext.toAst(conf: ToAstConfiguration = ToAstCon
internal fun RpgParser.DurationCodeContext.toAst(conf: ToAstConfiguration = ToAstConfiguration()): DurationCode =
when {
SPLAT_MSECONDS() != null || SPLAT_MS() != null -> DurationInMSecs
SPLAT_SECONDS() != null || SPLAT_S() != null -> DurationInSecs
SPLAT_MINUTES() != null || SPLAT_MN() != null -> DurationInMinutes
SPLAT_HOURS() != null || SPLAT_H() != null -> DurationInHours
SPLAT_DAYS() != null || SPLAT_D() != null -> DurationInDays
SPLAT_MONTHS() != null || SPLAT_M() != null -> DurationInMonths
SPLAT_YEARS() != null || SPLAT_Y() != null -> DurationInYears
else -> todo(conf = conf)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.smeup.rpgparser.smeup

import com.smeup.rpgparser.interpreter.TimeStampValue
import com.smeup.rpgparser.parsing.parsetreetoast.AstResolutionError
import org.junit.Test
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.temporal.ChronoUnit
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith

Expand Down Expand Up @@ -30,4 +33,34 @@ open class MULANGT04EssentialsCodopAndBifTest : MULANGTTest() {
)
assertEquals(expected, "smeup/T04_A80_P05".outputOf())
}

/**
* %DIFF with several DurationCodes
* @see #LS24003282
*/
@Test
fun executeMUDRNRAPU00228() {
val referenceDate = TimeStampValue.of("2024-07-10-10.25.27.921456")
val epochDate = TimeStampValue.of("1970-01-01-00.00.00.000000")
val referenceInstant = referenceDate.asTimeStamp().value.atZone(ZoneId.systemDefault()).toInstant()
val epochInstant = epochDate.asTimeStamp().value.atZone(ZoneId.systemDefault()).toInstant()

val mseconds = ChronoUnit.MICROS.between(epochInstant, referenceInstant).toString()
val seconds = ChronoUnit.SECONDS.between(epochInstant, referenceInstant).toString()
val minutes = ChronoUnit.MINUTES.between(epochInstant, referenceInstant).toString()
val hours = ChronoUnit.HOURS.between(epochInstant, referenceInstant).toString()
val days = ChronoUnit.DAYS.between(epochInstant, referenceInstant).toString()
val months = ChronoUnit.MONTHS.between(epochDate.localDate, referenceDate.localDate).toString()
val years = ChronoUnit.YEARS.between(epochDate.localDate, referenceDate.localDate).toString()
val expected = listOf(
mseconds, mseconds,
seconds, seconds,
minutes, minutes,
hours, hours,
days, days,
months, months,
years, years
)
assertEquals(expected, "smeup/MUDRNRAPU00228".outputOf())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
D ut S 30 0
D dt S Z INZ(Z'2024-07-10-10.25.27.921456')
D t S Z INZ(Z'1970-01-01-00.00.00.000000')

C EVAL ut=%diff(dt:t:*mseconds)
C ut DSPLY
C EVAL ut=%diff(dt:t:*ms)
C ut DSPLY
C EVAL ut=%diff(dt:t:*seconds)
C ut DSPLY
C EVAL ut=%diff(dt:t:*s)
C ut DSPLY
C EVAL ut=%diff(dt:t:*minutes)
C ut DSPLY
C EVAL ut=%diff(dt:t:*mn)
C ut DSPLY
C EVAL ut=%diff(dt:t:*hours)
C ut DSPLY
C EVAL ut=%diff(dt:t:*h)
C ut DSPLY
C EVAL ut=%diff(dt:t:*days)
C ut DSPLY
C EVAL ut=%diff(dt:t:*d)
C ut DSPLY
C EVAL ut=%diff(dt:t:*months)
C ut DSPLY
C EVAL ut=%diff(dt:t:*m)
C ut DSPLY
C EVAL ut=%diff(dt:t:*years)
C ut DSPLY
C EVAL ut=%diff(dt:t:*y)
C ut DSPLY

0 comments on commit 61323ee

Please sign in to comment.