Skip to content

Commit

Permalink
Merge pull request #204 from NIAEFEUP/fix/dateTime
Browse files Browse the repository at this point in the history
Added time to DateInterval
  • Loading branch information
rubuy-74 authored Nov 15, 2024
2 parents 55ddb2d + 1c80b7c commit 79f660c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ build/
!**/src/main/**/build/
!**/src/test/**/build/
docs/
static/

### STS ###
.apt_generated
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ server.error.whitelabel.enabled=false
# Jackson
spring.jackson.default-property-inclusion=non_null
spring.jackson.deserialization.fail-on-null-creator-properties=true
spring.jackson.date-format=dd-MM-yyyy
spring.jackson.date-format=dd-MM-yyyy HH:mm
spring.jackson.time-zone=Europe/Lisbon

# Auth Config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ internal class EventControllerTest @Autowired constructor(
"cool-image.png",
"https://docs.google.com/forms",
DateInterval(
TestUtils.createDate(2022, Calendar.JULY, 28),
TestUtils.createDate(2022, Calendar.JULY, 30)
TestUtils.createDate(2022, Calendar.JULY, 28, 10, 30),
TestUtils.createDate(2022, Calendar.JULY, 30, 11, 30)
),
"FEUP",
"Great Events"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ internal class ProjectControllerTest @Autowired constructor(
.andDocumentErrorResponse(documentation, hasRequestPayload = true)
},
requiredFields = mapOf(
"date" to "22-07-2021",
"date" to "22-07-2021 00:00",
"description" to "test description"
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package pt.up.fe.ni.website.backend.utils

import java.util.Calendar
import java.util.Date
import java.util.TimeZone
import java.util.*
import org.springframework.test.context.transaction.TestTransaction

class TestUtils {
companion object {
fun createDate(year: Int, month: Int, day: Int): Date {
fun createDate(year: Int, month: Int, day: Int, hour: Int = 0, minute: Int = 0): Date {
return Calendar.getInstance(TimeZone.getTimeZone("UTC"))
.apply { set(year, month, day, 0, 0, 0) }
.apply { set(year, month, day, hour, minute, 0) }
.time
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pt.up.fe.ni.website.backend.utils

import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import org.springframework.http.MediaType
import org.springframework.test.web.servlet.ResultActions
Expand Down Expand Up @@ -115,8 +115,8 @@ class ValidationTester(

fun isPastDate() {
// get the current date and offset it by 1 day
val timeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy")
val tomorrow = LocalDate.now()
val timeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm")
val tomorrow = LocalDateTime.now()
.plusDays(1)
.format(timeFormatter)
.toString()
Expand All @@ -141,8 +141,8 @@ class ValidationTester(
)

params[param] = mapOf(
"startDate" to "09-01-2023",
"endDate" to "08-01-2023"
"startDate" to "09-01-2023 00:00",
"endDate" to "08-01-2023 00:00"
)
req(params)
.expectValidationError()
Expand Down

0 comments on commit 79f660c

Please sign in to comment.