diff --git a/obp-api/src/main/scala/code/api/util/APIUtil.scala b/obp-api/src/main/scala/code/api/util/APIUtil.scala index ab51a247b..94a1c2362 100644 --- a/obp-api/src/main/scala/code/api/util/APIUtil.scala +++ b/obp-api/src/main/scala/code/api/util/APIUtil.scala @@ -159,13 +159,15 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ oneYearAgo.getTime() } def DefaultToDate = new Date() - def DefaultFromDate = oneYearAgo(DefaultToDate) + def oneYearAgoFromDate = oneYearAgo(DefaultToDate) def formatDate(date : Date) : String = { CustomJsonFormats.losslessFormats.dateFormat.format(date) } - def DefaultFromDateString = formatDate(DefaultFromDate) + def oneYearAgoFromDateString = formatDate(oneYearAgoFromDate) def DefaultToDateString = formatDate(DefaultToDate) + + val epochTime = new Date(0) // Set epoch time. The Unix epoch is 00:00:00 UTC on 1 January 1970. implicit def errorToJson(error: ErrorMessage): JValue = Extraction.decompose(error) val headers = ("Access-Control-Allow-Origin","*") :: Nil @@ -867,7 +869,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ case (_, Full(right)) => parseObpStandardDate(right.head) case _ => - Full(new Date(0)) // Set epoch time. The Unix epoch is 00:00:00 UTC on 1 January 1970. + Full(epochTime) // Set epoch time. The Unix epoch is 00:00:00 UTC on 1 January 1970. } date.map(OBPFromDate(_)) } @@ -1920,7 +1922,7 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{ val dateParameter = if(containsDate){ s""" | - |* from_date=DATE => example value: $DefaultFromDateString. NOTE! The default value is one year ago ($DefaultFromDateString). + |* from_date=DATE => example value: $oneYearAgoFromDateString. NOTE! The default value is one year ago ($oneYearAgoFromDateString). |* to_date=DATE => example value: $DefaultToDateString. NOTE! The default value is now ($DefaultToDateString). | |Date format parameter: $DateWithMs($DateWithMsExampleString) ==> time zone is UTC. diff --git a/obp-api/src/test/scala/code/util/APIUtilTest.scala b/obp-api/src/test/scala/code/util/APIUtilTest.scala index cebb40c52..871786f31 100644 --- a/obp-api/src/test/scala/code/util/APIUtilTest.scala +++ b/obp-api/src/test/scala/code/util/APIUtilTest.scala @@ -49,6 +49,7 @@ class APIUtilTest extends FeatureSpec with Matchers with GivenWhenThen with Prop val DefaultToDateString = APIUtil.DefaultToDateString val startDateObject: Date = DateWithMsFormat.parse(DefaultFromDateString) val endDateObject: Date = DateWithMsFormat.parse(DefaultToDateString) + val epochTime = new Date(0) // Set epoch time. The Unix epoch is 00:00:00 UTC on 1 January 1970. ZonedDateTime.now(ZoneId.of("UTC")) feature("test APIUtil.dateRangesOverlap method") { @@ -235,7 +236,7 @@ class APIUtilTest extends FeatureSpec with Matchers with GivenWhenThen with Prop scenario("test the wrong case: wrong name (wrongName) in HTTPParam") { val httpParams: List[HTTPParam] = List(HTTPParam("wrongName", List(s"$DateWithMsExampleString"))) - val startTime = OBPFromDate(DefaultFromDate) + val startTime = OBPFromDate(epochTime) val returnValue = getFromDate(httpParams) returnValue shouldBe a[Full[OBPFromDate]] @@ -247,7 +248,7 @@ class APIUtilTest extends FeatureSpec with Matchers with GivenWhenThen with Prop scenario("test the wrong case: wrong name (wrongName) and wrong values (wrongValue) in HTTPParam") { val httpParams: List[HTTPParam] = List(HTTPParam("wrongName", List("wrongValue"))) - val startTime = OBPFromDate(DefaultFromDate) + val startTime = OBPFromDate(epochTime) val returnValue = getFromDate(httpParams) returnValue shouldBe a[Full[OBPFromDate]]