This commit is contained in:
pika 2025-06-16 12:00:46 +02:00
parent ee3a12901e
commit 9c3a3e06b2
2 changed files with 43 additions and 48 deletions

View file

@ -24,62 +24,41 @@ Column {
if (!root.selectedStartDate) return
if (root.selectedStartDate && root.selectedEndDate) {
const diffTime = Math.abs(root.selectedEndDate - root.selectedStartDate)
const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24))
root.dateCalculation = diffDays + " days"
// For range selection, just count the days between dates
const start = new Date(root.selectedStartDate.getFullYear(), root.selectedStartDate.getMonth(), root.selectedStartDate.getDate())
const end = new Date(root.selectedEndDate.getFullYear(), root.selectedEndDate.getMonth(), root.selectedEndDate.getDate())
const diffDays = Math.round((end - start) / (1000 * 60 * 60 * 24))
root.dateCalculation = Math.abs(diffDays) + " days"
} else {
const today = new Date()
today.setHours(0, 0, 0, 0) // Normalize to start of day
const selectedDate = new Date(root.selectedStartDate)
selectedDate.setHours(0, 0, 0, 0) // Normalize to start of day
const diffTime = selectedDate - today
const direction = diffTime > 0 ? "until" : "since"
let diffDays = Math.floor(Math.abs(diffTime) / (1000 * 60 * 60 * 24))
// For future dates, ensure we start at 1
if (direction === "until") {
// If it's the same day, show 0 days
if (diffDays === 0) {
root.dateCalculation = "0 days"
return
}
// For next day and beyond, add 1
diffDays += 1
// For single date selection, compare with today
const today = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate())
const selected = new Date(root.selectedStartDate.getFullYear(), root.selectedStartDate.getMonth(), root.selectedStartDate.getDate())
const diffDays = Math.round((selected - today) / (1000 * 60 * 60 * 24))
if (diffDays === 0) {
root.dateCalculation = "0 days"
} else if (diffDays > 0) {
root.dateCalculation = diffDays + " days until"
} else {
diffDays = Math.max(1, diffDays - 1)
root.dateCalculation = Math.abs(diffDays) + " days since"
}
root.dateCalculation = diffDays + " days " + direction
}
}
function calculateDaysFromReference(referenceDate, targetDate) {
if (!referenceDate || !targetDate) return
const refDate = new Date(referenceDate)
refDate.setHours(0, 0, 0, 0) // Normalize to start of day
const targDate = new Date(targetDate)
targDate.setHours(0, 0, 0, 0) // Normalize to start of day
const diffTime = targDate - refDate
const direction = diffTime > 0 ? "until" : "since"
let diffDays = Math.floor(Math.abs(diffTime) / (1000 * 60 * 60 * 24))
// For future dates, ensure we start at 1
if (direction === "until") {
// If it's the same day, show 0 days
if (diffDays === 0) {
root.dateCalculation = "0 days"
return
}
// For next day and beyond, add 1
diffDays += 1
const ref = new Date(referenceDate.getFullYear(), referenceDate.getMonth(), referenceDate.getDate())
const target = new Date(targetDate.getFullYear(), targetDate.getMonth(), targetDate.getDate())
const diffDays = Math.round((target - ref) / (1000 * 60 * 60 * 24))
if (diffDays === 0) {
root.dateCalculation = "0 days"
} else if (diffDays > 0) {
root.dateCalculation = diffDays + " days until"
} else {
diffDays = Math.max(1, diffDays - 1)
root.dateCalculation = Math.abs(diffDays) + " days since"
}
root.dateCalculation = diffDays + " days " + direction
}
function resetSelection() {
@ -222,8 +201,7 @@ Column {
id: monthView
anchors.fill: parent
anchors.margins: 12
anchors.rightMargin: 4 // Reduced right margin
anchors.bottomMargin: 16 // Keep the bottom margin
anchors.rightMargin: 0 // Reduced right margin
orientation: ListView.Horizontal
snapMode: ListView.SnapOneItem
highlightRangeMode: ListView.StrictlyEnforceRange
@ -259,9 +237,23 @@ Column {
model: 12 // Show all months
currentIndex: new Date().getMonth()
// Ensure current month is active when calendar opens
Component.onCompleted: {
currentIndex = new Date().getMonth()
}
delegate: Grid {
width: monthView.width
height: monthView.height
opacity: monthView.currentIndex === index ? 1 : 0.2 // Dim non-current months
Behavior on opacity {
NumberAnimation {
duration: Appearance.anim.durations.normal
easing.type: Easing.BezierSpline
easing.bezierCurve: Appearance.anim.curves.standard
}
}
columns: 7
spacing: Appearance.spacing.small