commit 03/09/2025
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package codes
|
||||
|
||||
import content.ScheduleDay
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
@@ -23,6 +24,7 @@ class Somecodes {
|
||||
val datetimeformat1: DateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss")
|
||||
val dateformat1: DateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy")
|
||||
val timeformat1: DateTimeFormatter = DateTimeFormatter.ofPattern("hh:mm:ss")
|
||||
val timeformat2: DateTimeFormatter = DateTimeFormatter.ofPattern("hh:mm")
|
||||
const val KB_threshold = 1024.0
|
||||
const val MB_threshold = KB_threshold * 1024.0
|
||||
const val GB_threshold = MB_threshold * 1024.0
|
||||
@@ -165,6 +167,52 @@ class Somecodes {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string is a valid schedule time in the format "HH:mm".
|
||||
* @param value The string to check.
|
||||
* @return True if the string is a valid schedule time, false otherwise.
|
||||
*/
|
||||
fun ValidScheduleTime(value: String): Boolean{
|
||||
// format HH:mm
|
||||
try {
|
||||
if (ValidString(value)){
|
||||
timeformat2.parse(value)
|
||||
return true
|
||||
}
|
||||
} catch (_ : Exception){
|
||||
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a schedule day by its name.
|
||||
* @param value The name of the schedule day to find.
|
||||
* @return The name of the schedule day if found, null otherwise.
|
||||
*/
|
||||
fun FindScheduleDay(value: String) : String? {
|
||||
val sd = ScheduleDay.entries.find { sd -> sd.name == value }
|
||||
return sd?.name
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string is a valid schedule day or a valid date.
|
||||
* A valid schedule day is either one of the ScheduleDay enum names or a date in the format "dd/MM/yyyy".
|
||||
* @param value The string to check.
|
||||
* @return True if the string is a valid schedule day or date, false otherwise.
|
||||
*/
|
||||
fun ValidScheduleDay(value: String) : Boolean {
|
||||
if (ValidString(value)){
|
||||
// check if value is one of ScheduleDay enum name
|
||||
if (FindScheduleDay(value) != null){
|
||||
return true
|
||||
}
|
||||
// check if value is in format dd/MM/yyyy
|
||||
return ValidDate(value)
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user