diff --git a/src/commonMain/kotlin/de/kif/common/ConstraintChecking.kt b/src/commonMain/kotlin/de/kif/common/ConstraintChecking.kt index f7722fb..097ae7c 100644 --- a/src/commonMain/kotlin/de/kif/common/ConstraintChecking.kt +++ b/src/commonMain/kotlin/de/kif/common/ConstraintChecking.kt @@ -164,8 +164,8 @@ fun checkConstraints( if ( s.workGroup.id == constraint.workGroup && schedule.day == s.day && - start <= s.getAbsoluteEndTime() && - s.getAbsoluteStartTime() <= end + start < s.getAbsoluteEndTime() && + s.getAbsoluteStartTime() < end ) { errors += ConstraintError("Work group requires not same time with ${s.workGroup.name}!") } diff --git a/src/jsMain/kotlin/de/kif/frontend/views/calendar/Calendar.kt b/src/jsMain/kotlin/de/kif/frontend/views/calendar/Calendar.kt index 6c21432..c049313 100644 --- a/src/jsMain/kotlin/de/kif/frontend/views/calendar/Calendar.kt +++ b/src/jsMain/kotlin/de/kif/frontend/views/calendar/Calendar.kt @@ -26,11 +26,11 @@ class Calendar(calendar: HTMLElement) : View(calendar) { private val htmlBody = document.body ?: createHtmlView() - val day = calendarTable.dataset["day"]?.toIntOrNull() ?: -1 - val reloadOnFinish = calendarTable.dataset["reload"]?.toBoolean() ?: false - val referenceDate = calendarTable.dataset["reference"]?.toLongOrNull() ?: -1L - val nowDate = calendarTable.dataset["now"]?.toLongOrNull() ?: -1L - val timeDifference = Date.now().toLong() - nowDate + val day = (calendarTable.dataset["day"]?.toIntOrNull() ?: -1).also { println(it) } + val reloadOnFinish = (calendarTable.dataset["reload"]?.toBoolean() ?: false).also { println(it) } + val referenceDate = (calendarTable.dataset["reference"]?.toLongOrNull() ?: -1L).also { println(it) } + val nowDate = (calendarTable.dataset["now"]?.toLongOrNull() ?: -1L).also { println(it) } + val timeDifference = (Date.now().toLong() - nowDate).also { println(it) } fun scrollVerticalBy(pixel: Double, scrollBehavior: ScrollBehavior = ScrollBehavior.SMOOTH) { scrollAllVerticalBy(pixel, scrollBehavior) @@ -226,4 +226,4 @@ class Calendar(calendar: HTMLElement) : View(calendar) { fun initCalendar() { document.getElementsByClassName("calendar").iterator().forEach { Calendar(it) } -} \ No newline at end of file +} diff --git a/src/jsMain/kotlin/de/kif/frontend/views/calendar/CalendarBody.kt b/src/jsMain/kotlin/de/kif/frontend/views/calendar/CalendarBody.kt index a20cf37..5c34148 100644 --- a/src/jsMain/kotlin/de/kif/frontend/views/calendar/CalendarBody.kt +++ b/src/jsMain/kotlin/de/kif/frontend/views/calendar/CalendarBody.kt @@ -15,6 +15,13 @@ import kotlin.js.Date import kotlin.math.max import kotlin.math.min +fun getYearOfDate(date: Date): Int { + return ((Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) - Date.UTC( + date.getFullYear(), + 0, + 0 + )) / 24 / 60 / 60 / 1000).toInt() +} class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection(view) { @@ -26,6 +33,9 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection get() = iterator().asSequence().flatten().toList() + var maxTime = 0 + var minTime = 0 + private suspend fun updateRows(startTime: Int? = null, length: Int = 0) { if (calendarEntries.isEmpty() && startTime == null && !editable) { for (row in iterator().asSequence().toList()) { @@ -64,6 +74,18 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection first().time) { remove(first()) } @@ -87,10 +109,11 @@ class CalendarBody(val calendar: Calendar, view: HTMLElement) : ViewCollection = mutableListOf() + } } diff --git a/src/jvmMain/kotlin/de/kif/backend/route/Board.kt b/src/jvmMain/kotlin/de/kif/backend/route/Board.kt index 5df9215..6a92f63 100644 --- a/src/jvmMain/kotlin/de/kif/backend/route/Board.kt +++ b/src/jvmMain/kotlin/de/kif/backend/route/Board.kt @@ -51,10 +51,11 @@ fun Route.board() { val referenceTime = Configuration.Schedule.referenceDate.time val refDate = Configuration.Schedule.referenceDate + val todayDate = now - val refDay = refDate.time / (1000 * 60 * 60 * 24) - val todayDay = now.time / (1000 * 60 * 60 * 24) - val day = (todayDay - refDay).toInt() + val refDay = Calendar.getInstance().also { it.time = todayDate }.get(Calendar.DAY_OF_YEAR) + val todayDay = Calendar.getInstance().also { it.time = refDate }.get(Calendar.DAY_OF_YEAR) + val day = todayDay - refDay val list = ScheduleRepository.getByDay(day) val rooms = RoomRepository.all() diff --git a/src/jvmMain/kotlin/de/kif/backend/route/Calendar.kt b/src/jvmMain/kotlin/de/kif/backend/route/Calendar.kt index c73f488..e7b351e 100644 --- a/src/jvmMain/kotlin/de/kif/backend/route/Calendar.kt +++ b/src/jvmMain/kotlin/de/kif/backend/route/Calendar.kt @@ -1,7 +1,7 @@ package de.kif.backend.route -import com.soywiz.klock.* -import com.soywiz.klock.jvm.toDateTime +import com.soywiz.klock.DateTime +import com.soywiz.klock.days import de.kif.backend.Configuration import de.kif.backend.isAuthenticated import de.kif.backend.prefix @@ -77,10 +77,13 @@ fun DIV.renderCalendar( val gridLabelWidth = 60 val minutesOfDay = to - from + val refDate = Configuration.Schedule.referenceDate + val todayDate = Date() val now = Calendar.getInstance() - val d = (now.timeInMillis / (1000 * 60 * 60 * 24) - - Configuration.Schedule.referenceDate.time / (1000 * 60 * 60 * 24)).toInt() - val diff = day - d + val refDay = Calendar.getInstance().also { it.time = todayDate }.get(Calendar.DAY_OF_YEAR) + val todayDay = Calendar.getInstance().also { it.time = refDate }.get(Calendar.DAY_OF_YEAR) + val diff = day - (todayDay - refDay) + val currentTime = now.get(Calendar.HOUR_OF_DAY) * 60 + now.get(Calendar.MINUTE) + (diff * 60 * 24) div("calendar-table") { @@ -188,8 +191,8 @@ fun Route.calendar() { val refDate = Configuration.Schedule.referenceDate val todayDate = Date() - val refDay = refDate.time / (1000 * 60 * 60 * 24) - val todayDay = todayDate.time / (1000 * 60 * 60 * 24) + val refDay = Calendar.getInstance().also { it.time = todayDate }.get(Calendar.DAY_OF_YEAR) + val todayDay = Calendar.getInstance().also { it.time = refDate }.get(Calendar.DAY_OF_YEAR) val day = todayDay - refDay call.respondRedirect("$prefix/calendar/$day", false)