Hmm a very complex VB script seems to work fine but then I added this simple function.
Works in Excell but not in LibreOffice.
Function YDAYS(D As Date) As Integer
Dim y, m As Integer
y = Year(D)
YDAYS = 365
If y Mod 400 = 0 Then
YDAYS = 366
ElseIf y Mod 100 = 0 Then
ElseIf y Mod 4 = 0 Then
YDAYS = 366
End If
End Function