#1364: DatePrecision.kt
projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt Kotlin class, projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt 105 lines · 66 code · 35 comments · 4 blank
Purpose: Source file: projectforge/framework/time/DatePrecision.kt. DatePrecision.kt is part of the ProjectForge open-source project management application.
Source (first 100 lines)
/////////////////////////////////////////////////////////////////////////////
//
// Project ProjectForge Community Edition
// www.projectforge.org
//
// Copyright (C) 2001-2026 Micromata GmbH, Germany (www.micromata.com)
//
// ProjectForge is dual-licensed.
//
// This community edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as published
// by the Free Software Foundation; version 3 of the License.
//
// This community edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
// Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, see http://www.gnu.org/licenses/.
//
/////////////////////////////////////////////////////////////////////////////
package org.projectforge.framework.time
import java.time.ZonedDateTime
/**
*
* @author Kai Reinhard (k.reinhard@micromata.de)
*/
enum class DatePrecision {
/** Precision millisecond (nanos will be a multiplier of thousands). */
MILLISECOND {
override fun ensurePrecision(dateTime: ZonedDateTime): ZonedDateTime {
val nanos = dateTime.nano / 1000 * 1000
return dateTime.withNano(nanos)
}
},
/** Nanos/milliseconds will be set to zero. */
SECOND {
override fun ensurePrecision(dateTime: ZonedDateTime): ZonedDateTime {
return dateTime.withNano(0)
}
},
/** Milliseconds and seconds will be set to zero. */
MINUTE {
override fun ensurePrecision(dateTime: ZonedDateTime): ZonedDateTime {
return SECOND.ensurePrecision(dateTime).withSecond(0)
}
},
/** Milliseconds and seconds will be set to zero, minutes to 0, 5, 10, 15 etc. */
MINUTE_5 {
override fun ensurePrecision(dateTime: ZonedDateTime): ZonedDateTime {
val minute = dateTime.minute
var i = 3
var newMinute = minute
while (i < 60) {
if (minute < i) {
newMinute = i - 3
break
}
i += 5
}
if (newMinute > 57) {
return MINUTE.ensurePrecision(dateTime).withMinute(0).plusHours(1)
}
return MINUTE.ensurePrecision(dateTime).withMinute(newMinute)
}
},
/**
* Milliseconds and seconds will be set to zero, minutes to 0, 15, 30 or 45.
*/
MINUTE_15 {
override fun ensurePrecision(dateTime: ZonedDateTime): ZonedDateTime {
val dt = MINUTE.ensurePrecision(dateTime)
val minute = dt.minute
if (minute < 8) {
return dt.withMinute(0)
} else if (minute < 23) {
return dt.withMinute(15)
} else if (minute < 38) {
return dt.withMinute(30)
} else if (minute < 53) {
return dt.withMinute(45)
} else {
return dt.withMinute(0).plusHours(1)
}
}
},
/** Milliseconds, seconds and minutes will be set to zero. */
HOUR_OF_DAY {
override fun ensurePrecision(dateTime: ZonedDateTime): ZonedDateTime {
return MINUTE.ensurePrecision(dateTime).withMinute(0)
}
},
/** Milliseconds, seconds, minutes and hours will be set to zero. */
DAY {
override fun ensurePrecision(dateTime: ZonedDateTime): ZonedDateTime {
return HOUR_OF_DAY.ensurePrecision(dateTime).withHour(0)
Git History
868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
b6092df09 Copyright 2023 -> 2024
ab45d51fa Copyright 2001-2022 -> 2001-2023.
5f7ef41b8 Copyright 2021 -> 2022
868d6abb7
2025 -> 2026868d6abb75cd191a892911ac8e45058932cf9074
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt b/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt
index 54b29460e..200f61bd6 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt
@@ -3,7 +3,7 @@
// Project ProjectForge Community Edition
// www.projectforge.org
//
-// Copyright (C) 2001-2025 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2026 Micromata GmbH, Germany (www.micromata.com)
//
// ProjectForge is dual-licensed.
//
63081666f
Source file headers: 2024-> 2025.63081666f620fb87315f01b817e560e0b2f6a33a
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt b/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt
index 9edf2f3ee..54b29460e 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt
@@ -3,7 +3,7 @@
// Project ProjectForge Community Edition
// www.projectforge.org
//
-// Copyright (C) 2001-2024 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2025 Micromata GmbH, Germany (www.micromata.com)
//
// ProjectForge is dual-licensed.
//
b6092df09
Copyright 2023 -> 2024b6092df0927c4a3b161e888445f31dcab57493f2
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt b/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt
index fd4b63148..9edf2f3ee 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt
@@ -3,7 +3,7 @@
// Project ProjectForge Community Edition
// www.projectforge.org
//
-// Copyright (C) 2001-2023 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2024 Micromata GmbH, Germany (www.micromata.com)
//
// ProjectForge is dual-licensed.
//
ab45d51fa
Copyright 2001-2022 -> 2001-2023.ab45d51fa419ede6174b31d69987f96d4b841ff9
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt b/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt
index 9b7cac8d5..fd4b63148 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt
@@ -3,7 +3,7 @@
// Project ProjectForge Community Edition
// www.projectforge.org
//
-// Copyright (C) 2001-2022 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2023 Micromata GmbH, Germany (www.micromata.com)
//
// ProjectForge is dual-licensed.
//
5f7ef41b8
Copyright 2021 -> 20225f7ef41b8cbbf29b1bff094f0c0b708dcaecb19e
diff --git a/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt b/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt
index 257a1d397..9b7cac8d5 100644
--- a/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt
+++ b/projectforge-business/src/main/kotlin/org/projectforge/framework/time/DatePrecision.kt
@@ -3,7 +3,7 @@
// Project ProjectForge Community Edition
// www.projectforge.org
//
-// Copyright (C) 2001-2021 Micromata GmbH, Germany (www.micromata.com)
+// Copyright (C) 2001-2022 Micromata GmbH, Germany (www.micromata.com)
//
// ProjectForge is dual-licensed.
//