alan. iselin Der gesamte Code aus dem Beispiel muß eingefügt werden. Die letzte Zeile ist nur der Aufruf der Funktion. Versuche das mal so.
function TimeInterval(first : datetime,second : datetime) do
let dateTime1 := first;
let dateTime2 := second;
let D1 := if dateTime1 < dateTime2 then
date(dateTime1)
else
date(dateTime2)
end;
let D2 := if dateTime1 < dateTime2 then
date(dateTime2)
else
date(dateTime1)
end;
"Funktion zur Überprüfung eines Datums, ob es in einem Schaltjahr liegt";
function isLeapYear(num : number) do
if date(num, 2, 29) != date(num, 3, 1) then
true
else
false
end
end;
let timeZone := number(format(dateTime1, "ZZ")) - number(format(dateTime2, "ZZ"));
let timeDuration := 1;
switch timeDuration do
case timeZone = -100:
(timeDuration := number(time(24, 0) - time(dateTime1) + time(dateTime2) - time(1, 0)))
case timeZone = 100:
(timeDuration := number(time(24, 0) - time(dateTime1) + time(dateTime2) + time(1, 0)))
case timeZone = 0:
(timeDuration := number(time(24, 0) - time(dateTime1) + time(dateTime2)))
end;
"Funktion als Variable zur Überprüfung ob ein Zeitabstand >= ein Tag ist.";
let isFullDayOrMore := timeDuration - 86400000 >= 0;
let oneDayMs := 86400000;
let oneHourMs := 3600000;
let oneMinuteMs := 60000;
let dayMs := floor(timeDuration / oneDayMs) * oneDayMs;
let hourMs := floor((timeDuration - dayMs) / oneHourMs) * oneHourMs;
let minuteMs := floor((timeDuration - dayMs - hourMs) / oneMinuteMs) * oneMinuteMs;
let HH := hourMs / oneHourMs;
let mm := minuteMs / oneMinuteMs;
let DD := 1;
let MM := 1;
let YY := 1;
if D1 = null or D2 = null then
""
else
if D1 = D2 and timeDuration = 86400000 then
"Anfang = Ende"
else
"Berechnung der Tage";
let sameDayOfD1InMonthBeforeOfD2 := day(date(year(D2), month(D2) - 1, day(D1)));
let lastDayOfD1 := day(date(year(D2), month(D2), 0));
switch DD do
case day(D2) = day(D1) and isFullDayOrMore:
(DD := 0)
case day(D2) > day(D1) and isFullDayOrMore:
(DD := day(D2) - day(D1))
case day(D2) = day(D1) and not isFullDayOrMore:
(DD := lastDayOfD1 - sameDayOfD1InMonthBeforeOfD2 + day(D2) - 1)
case day(D2) > day(D1) - 1 and not isFullDayOrMore:
(DD := day(D2) - day(D1) - 1)
case day(D2) < day(D1) and not isFullDayOrMore and isLeapYear(year(D1)) and month(D1) = 2 and month(D2) = 3:
(DD := 29 - if day(D1) = 29 then
29
else
sameDayOfD1InMonthBeforeOfD2
end + day(D2) - 1)
case day(D2) < day(D1) and isFullDayOrMore and isLeapYear(year(D1)) and month(D1) = 2 and month(D2) = 3:
(DD := 29 - if day(D1) = 29 then
29
else
sameDayOfD1InMonthBeforeOfD2
end + day(D2))
case day(D2) < day(D1) and not isFullDayOrMore:
(DD := lastDayOfD1 - sameDayOfD1InMonthBeforeOfD2 + day(D2) - 1)
case day(D2) < day(D1) and isFullDayOrMore:
(DD := lastDayOfD1 - sameDayOfD1InMonthBeforeOfD2 + day(D2))
end;
"Berechnung der Monate";
switch MM do
case month(D1) < month(D2) and day(D1) <= day(D2) and isFullDayOrMore:
(MM := month(D2) - month(D1))
case month(D1) < month(D2) and day(D1) < day(D2) and not isFullDayOrMore:
(MM := month(D2) - month(D1))
case month(D1) < month(D2) and day(D1) > day(D2) and isFullDayOrMore:
(MM := month(D2) - month(D1) - 1)
case month(D1) < month(D2) and day(D1) >= day(D2) and not isFullDayOrMore:
(MM := month(D2) - month(D1) - 1)
case month(D1) > month(D2) and day(D1) > day(D2) and isFullDayOrMore:
(MM := 12 - month(D1) + month(D2) - 1)
case month(D1) > month(D2) and day(D1) >= day(D2) and not isFullDayOrMore:
(MM := 12 - month(D1) + month(D2) - 1)
case month(D1) > month(D2) and day(D1) <= day(D2) and isFullDayOrMore:
(MM := 12 - month(D1) + month(D2))
case month(D1) > month(D2) and day(D1) < day(D2) and not isFullDayOrMore:
(MM := 12 - month(D1) + month(D2))
case month(D1) = month(D2) and day(D1) <= day(D2) and isFullDayOrMore:
(MM := 0)
case month(D1) = month(D2) and day(D1) < day(D2) and not isFullDayOrMore:
(MM := 0)
case month(D1) = month(D2) and day(D1) > day(D2) and isFullDayOrMore:
(MM := 11)
case month(D1) = month(D2) and day(D1) >= day(D2) and not isFullDayOrMore:
(MM := 11)
end;
"Berechnung der Jahre";
switch YY do
case month(D1) < month(D2):
(YY := year(D2) - year(D1))
case month(D1) = month(D2) and day(D1) <= day(D2) and isFullDayOrMore:
(YY := year(D2) - year(D1))
case month(D1) = month(D2) and day(D1) = day(D2) and not isFullDayOrMore:
(YY := year(D2) - year(D1) - 1)
case month(D1) = month(D2) and day(D1) < day(D2) and not isFullDayOrMore:
(YY := year(D2) - year(D1))
case month(D1) = month(D2) and day(D1) > day(D2):
(YY := year(D2) - year(D1) - 1)
case month(D1) > month(D2):
(YY := year(D2) - year(D1) - 1)
end
end
end;
"Das Anordnen der Ergebnisse.";
let yearResult := "";
switch yearResult != null do
case YY = 0:
(yearResult := "")
case YY = 1 and MM = 0 and DD = 0 and HH = 0 and mm = 0:
(yearResult := YY + " Jahr" + "")
case YY = 1:
(yearResult := YY + " Jahr" + ", ")
case YY > 1 and MM = 0 and DD = 0 and HH = 0 and mm = 0:
(yearResult := YY + " Jahre" + "")
case YY > 1:
(yearResult := YY + " Jahre" + ", ")
end;
let monthResult := "";
switch monthResult != null do
case MM = 0:
(monthResult := "")
case MM = 1 and DD = 0 and HH = 0 and mm = 0:
(monthResult := MM + " Monat" + "")
case MM = 1:
(monthResult := MM + " Monat" + ", ")
case MM > 1 and DD = 0 and HH = 0 and mm = 0:
(monthResult := MM + " Monate" + "")
case MM > 1:
(monthResult := MM + " Monate" + ", ")
end;
let dayResult := "";
switch dayResult != null do
case DD = 0:
(dayResult := "")
case DD = 1 and HH = 0 and mm = 0:
(dayResult := DD + " Tag" + "")
case DD = 1:
(dayResult := DD + " Tag" + ", ")
case DD > 1 and HH = 0 and mm = 0:
(dayResult := DD + " Tage" + "")
case DD > 1:
(dayResult := DD + " Tage" + ", ")
end;
let hourResult := "";
switch hourResult != null do
case HH = 0:
(hourResult := "")
case HH = 1 and mm = 0:
(hourResult := HH + " Stunde" + "")
case HH = 1:
(hourResult := HH + " Stunde" + ", ")
case HH > 1 and mm = 0:
(hourResult := HH + " Stunden" + "")
case HH > 1:
(hourResult := HH + " Stunden" + ", ")
end;
let minuteResult := "";
switch minuteResult != null do
case mm = 0:
(minuteResult := "")
case mm = 1:
(minuteResult := mm + " Minute")
case mm > 1:
(minuteResult := mm + " Minuten")
end;
yearResult + monthResult + dayResult + hourResult + minuteResult
end;
TimeInterval(datetime(first(Rechnung.'Data Dal')),datetime(first(Rechnung.'Data Al')))