Commit e667ac41 authored by Frank Bergmann's avatar Frank Bergmann

Absence interval: Now also accepting localized units

parent ef249116
......@@ -1061,22 +1061,28 @@ ad_proc -public im_absence_formatted_duration_to_days {
Examples: '1 day', '4 hours', '1' (=one day), '0.5' (=half a day)
} {
set days_formatted_1 [string trim [string tolower $days_formatted]]
set days_formatted_2 [string map {days d day d hours h hour h} $days_formatted_1]
set map_2 [list days d day d hours h hour h]
set days_formatted_2 [string map $map_2 $days_formatted_1]
# Also accept localized names for day, days, hour or hours
set map_3 [list [_ calendar.days] d [_ intranet-core.Day] d [_ calendar.Hours] h [_ intranet-core.Hour] h]
set map_3 [string tolower $map_3]
set days_formatted_3 [string map $map_3 $days_formatted_2]
set days ""
if {[regexp {^(.+)d} $days_formatted_2 match day_string]} {
if {[regexp {^(.+)d} $days_formatted_3 match day_string]} {
catch {
set days [expr 1.0 * [string trim $day_string]]
}
}
if {[regexp {^(.+)h} $days_formatted_2 match hour_string]} {
if {[regexp {^(.+)h} $days_formatted_3 match hour_string]} {
catch {
set days [expr [string trim $hour_string] / 8.0]
}
}
if {"" eq $days} {
catch {
set days [expr 1.0 * $days_formatted_2]
set days [expr 1.0 * $days_formatted_3]
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment