Skip to content

Commit d4d1c3c

Browse files
authored
Merge pull request #76 from fraenkelc/bugfix/Fix-edits-of-previous-days
Bugfix/fix edits of previous days
2 parents 5530797 + b5a911f commit d4d1c3c

File tree

4 files changed

+53
-7
lines changed

4 files changed

+53
-7
lines changed

src/main/antlr/org/stt/grammar/EnglishCommands.g4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ agoFormat returns [int amount] :
2727

2828
date: (NUMBER|DOT|MINUS|SLASH)+;
2929

30-
dateTimeInternal: (NUMBER|DOT|MINUS|SLASH|COLON)+;
30+
dateTimeInternal: (NUMBER|DOT|MINUS|SLASH|COLON|COMMA)+;
3131

3232
dateTime returns [String text]: txt=dateTimeInternal { $text = $txt.text; };
3333

@@ -84,6 +84,7 @@ reportStart returns [LocalDate from_date, LocalDate to_date]:
8484
// WHEN ADDING TOKENS: ADD THEM to anyToken above!!
8585
// SYMBOLS
8686
COLON: ':';
87+
COMMA: ',';
8788
DOT: '.';
8889
MINUS: '-';
8990
SLASH: '/';

src/main/kotlin/org/stt/command/CommandModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CommandModule {
3939
@Named("dateTimeFormatter")
4040
fun provideDateTimeFormatter(): DateTimeFormatter {
4141
return DateTimeFormatterBuilder()
42-
.appendLocalized(FormatStyle.MEDIUM, FormatStyle.MEDIUM)
42+
.appendLocalized(FormatStyle.SHORT, FormatStyle.MEDIUM)
4343
.toFormatter()
4444
}
4545

src/test/kotlin/org/stt/command/CommandFormatterTest.kt

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import java.time.temporal.ChronoField
2929
import java.time.temporal.ChronoUnit
3030
import java.util.*
3131
import javax.inject.Provider
32-
import kotlin.streams.toList
3332

3433
@RunWith(Theories::class)
3534
class CommandFormatterTest {
@@ -359,6 +358,43 @@ class CommandFormatterTest {
359358
assertThat(timeTrackingItems[1]!!.start.toLocalDate()).isEqualTo(LocalDate.of(2014, 6, 22))
360359
}
361360

361+
@Theory
362+
fun `text from asNewItemCommandText can be parsed and is equal in locale`(locale: Locale) {
363+
// GIVEN
364+
365+
val start = LocalDateTime.of(2024, 1, 22, 12, 0, 0)
366+
val stop = LocalDateTime.of(2024, 1, 22, 20, 0, 0)
367+
val activity = "test activity"
368+
369+
// WHEN
370+
val actual = executeWithLocale(locale) {
371+
val module = CommandModule()
372+
val sut = CommandFormatter(
373+
module.provideCommandTextParser(), module.provideDateTimeFormatter(), module.provideTimeFormatter()
374+
)
375+
val commandText = sut.asNewItemCommandText(TimeTrackingItem(activity, start, stop))
376+
sut.parse(commandText)
377+
}
378+
379+
// THEN
380+
assertThat(actual).isInstanceOf(NewActivity::class.java)
381+
val item = (actual as NewActivity).newItem
382+
assertThat(item.start).isEqualTo(start)
383+
assertThat(item.end).isEqualTo(stop)
384+
assertThat(item.activity).isEqualTo(activity)
385+
386+
}
387+
388+
private fun <T> executeWithLocale(locale: Locale, action: () -> T): T {
389+
val defaultLocale = Locale.getDefault()
390+
try {
391+
Locale.setDefault(locale)
392+
return action()
393+
} finally {
394+
Locale.setDefault(defaultLocale)
395+
}
396+
}
397+
362398
private fun executeCommand(command: String): Optional<TimeTrackingItem> {
363399
val cmdToExec = sut.parse(command)
364400
val testCommandHandler = TestCommandHandler()
@@ -435,6 +471,15 @@ class CommandFormatterTest {
435471
@field:DataPoints
436472
var hourFormats = arrayOf(hours("test %sh ago"), hours("test %shr ago"), hours("test %s hrs ago"), hours("test\n%shour ago"), hours("test %s hours ago"), hours("left 3 hours ago %s hours ago"))
437473

474+
@JvmField
475+
@field:DataPoints
476+
var locales = arrayOf(
477+
Locale.UK,
478+
// currently not supported due to 12-hour date format with "PM" suffix
479+
// Locale.US,
480+
Locale.GERMAN
481+
)
482+
438483
fun min(command: String): Command {
439484
return Command(command, "mins")
440485
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.stt.connector.jira
22

3+
import org.assertj.core.api.Assertions.assertThatThrownBy
34
import org.junit.Test
45
import org.stt.config.JiraConfig
56

@@ -10,10 +11,9 @@ internal class JiraClientTest {
1011
fun testErrorHandlingOfIssueRequest() {
1112
val jiraConfig = JiraConfig()
1213
jiraConfig.jiraURI = "https://jira.atlassian.net"
13-
try {
14+
assertThatThrownBy {
1415
JiraClient("dummy", null, jiraConfig.jiraURI!!).getIssue("JRA-7")
15-
} catch (e: Exception) {
16-
assert(e.message.equals("Couldn't find issue JRA-7. Cause: {\"errorMessage\": \"Site temporarily unavailable\"}"))
17-
}
16+
}.isInstanceOf(IssueDoesNotExistException::class.java)
17+
.hasMessageContainingAll("Couldn't find issue JRA-7", "\"errorMessage\": \"Site temporarily unavailable\"")
1818
}
1919
}

0 commit comments

Comments
 (0)