Created
March 12, 2013 20:26
-
-
Save sanmadjack/5146699 to your computer and use it in GitHub Desktop.
Takes a number of minutes as input, and outputs a string formatted as: 9d 09h 09m
Leaves off days/hours if not supplied
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Function FormatDuration(ByVal total As Integer) As String | |
Dim days As Integer = Math.Floor(total / (60 * 24)) | |
Dim hours As Integer = Math.Floor((total Mod (60 * 24)) / 60) | |
Dim minutes As Integer = (total Mod (60 * 24)) Mod 60 | |
Dim output As New StringBuilder | |
If days <> 0 Then | |
output.Append(days) | |
output.Append("d ") | |
End If | |
If output.Length = 0 Then | |
If hours <> 0 Then | |
output.Append(hours) | |
output.Append("h ") | |
End If | |
Else | |
output.Append(hours.ToString("00")) | |
output.Append("h ") | |
End If | |
If output.Length = 0 Then | |
If minutes <> 0 Then | |
output.Append(minutes) | |
output.Append("m") | |
End If | |
Else | |
output.Append(minutes.ToString("00")) | |
output.Append("m") | |
End If | |
If output.Length = 0 Then | |
output.Append("-") | |
End If | |
Return output.ToString | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment