Skip to content

Commit 80514ae

Browse files
committed
feat(Util): Add skill time
1 parent b41dd6b commit 80514ae

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Assets/JCSUnity/Scripts/Util/JCS_Time.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* $Notice: See LICENSE.txt for modification and distribution information
77
* Copyright © 2023 by Shen, Jen-Chieh $
88
*/
9+
using System;
910
using UnityEngine;
1011

1112
namespace JCSUnity
@@ -15,6 +16,12 @@ namespace JCSUnity
1516
/// </summary>
1617
public static class JCS_Time
1718
{
19+
/* Variables */
20+
21+
/* Setter & Getter */
22+
23+
/* Functions */
24+
1825
/// <summary>
1926
/// Get the delta time by type.
2027
/// </summary>
@@ -42,5 +49,29 @@ public static float DeltaTime(JCS_DeltaTimeType type)
4249

4350
return 0.0f;
4451
}
52+
53+
/// <summary>
54+
/// Return the time similar to skill time.
55+
///
56+
/// - For day: 1d
57+
/// - For hour: 2h
58+
/// - For minute: 3m
59+
/// - For second: 4s
60+
/// </summary>
61+
public static string Format(float seconds)
62+
{
63+
TimeSpan time = TimeSpan.FromSeconds(seconds);
64+
65+
if (time.Days > 0)
66+
return $"{time.Days}d";
67+
if (time.Hours > 0)
68+
return $"{time.Hours}h";
69+
if (time.Minutes > 0)
70+
return $"{time.Minutes}m";
71+
if (time.Seconds >= 0)
72+
return $"{time.Seconds}s";
73+
74+
return "";
75+
}
4576
}
4677
}

0 commit comments

Comments
 (0)