Option Strict Off
Imports System.Runtime.CompilerServices
Imports System.Linq.Expressions

Namespace Extensiones
    Public Module TimeSpanExtensions
        <Extension()>
        Public Function TimeSpanAHoraString(ByVal ts As TimeSpan?) As String
            If ts.HasValue AndAlso ts.Value.Ticks <> 0 Then
                If ts.Value.TotalMinutes < 0 Then
                    Return "-" & Fix(Math.Abs(ts.Value.TotalHours)).ToString.PadLeft(2, "0") & ":" & Math.Abs(CInt(ts.Value.Minutes)).ToString.PadLeft(2, "0")
                Else
                    Return Fix(Math.Abs(ts.Value.TotalHours)).ToString.PadLeft(2, "0") & ":" & Math.Abs(CInt(ts.Value.Minutes)).ToString.PadLeft(2, "0")
                End If
            Else
                Return "00:00"
            End If
        End Function
    End Module
End Namespace
