In Swift, this code shows a 31 day difference
let today = Date()
let future = Calendar.current.date(
byAdding: .day,
value: 31,
to: today
) ?? Date()
print(Calendar.current.dateComponents([.day], from: today, to: future).day ?? 0) // ~31 days
But when transpiled through Skip it only shows a 0 or 1 day difference between the two dates.
This is because this line in DateComponents.swift incorrectly maps the .day Swift case to java.util.Calendar.DAY_OF_MONTH, which only looks at "day of month" and ignores differences between months. Jan 1 and Feb 1 are treated the same.
Here's a workaround till this is fixed.
#if SKIP
let startDate = startDate(nocopy: true).toInstant().atZone(ZoneId.systemDefault()).toLocalDate()
let endDate = endDate.kotlin(nocopy: true).toInstant().atZone(ZoneId.systemDefault()).toLocalDate()
return ChronoUnit.DAYS.between(startDate, endDate).toInt()
#else
return Calendar.current.dateComponents([.day], from: startDate, to: endDate).day ?? 0
#endif
In Swift, this code shows a
31 daydifferenceBut when transpiled through Skip it only shows a
0 or 1 daydifference between the two dates.This is because this line in DateComponents.swift incorrectly maps the
.daySwift case tojava.util.Calendar.DAY_OF_MONTH, which only looks at "day of month" and ignores differences between months.Jan 1andFeb 1are treated the same.Here's a workaround till this is fixed.