Why i get runtime error when try to return date


#1
fun getBarTimeFromTouchLineInfo(lastTradedTime : Int, exchangeSegment : Int){
    val date = getBaseReferenceDate(exchangeSegment)
    date.seconds = date.seconds.plus(lastTradedTime)
    return Date(date.setMinutes(date.minutes.minus(1)))
}

error None of the following functions can be called with the arguments supplied. (Long) defined in java.util.Date (String!) defined in java.util.Date


#2

What is the exact error message you are getting?


#3

Don’t know if this answers the question, but kotlin doesn’t implicit convert numbers:

https://kotlinlang.org/docs/reference/basic-types.html#explicit-conversions


#4

A few problems with your function:

  1. It doesn’t have a return type, so returning a date won’t compile either.
  2. This is the RuntimeError - date.setMinutes() returns void. There is no Date constructor which takes void as a parameter.
  3. All date modifier methods have been deprecated for many years. You should use a Calendar instead.

Here’s a version which should work for you:

fun getBarTimeFromTouchLineInfo(lastTradedTime : Int, exchangeSegment : Int): Date {
    val cal = Calendar.getInstance()
    cal.setTime(getBaseReferenceDate(exchangeSegment))
    cal.add(Calendar.SECOND, lastTradedTime)
    cal.add(Calendar.MINUTE, -1)
    return Date(cal.timeInMillis)
}

#5

here we get error