Solved Timespan to format

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Jordan

Member
Jan 25, 2017
190
12
18
25
Scotland
Hello,

Mans was never the best at the old mathEMATICS at school so he is stuck on problem.

How does one convert X seconds into a nicely formatted Days, Hours, Minutes and seconds

I get you can convert a timespan into ticks, days, hours. minutes, seconds ect. with SKstuff but only works when you convert a timespan into a single hour or minute.. This does not work

Set {_test} to "86400 Seconds" parsed as timespan to converted days, hours, minutes and seconds

Just returns 1 day, 1 hour, 1 minute, 1 second

I read up on integer division and some operator like % but then got confused and gave up :emoji_wink:

Much help would be appreciated.

I'm also aware you can display a timespan but it does not display Days, Hours, Minutes and seconds. all at once.
 
Use @EWS's snippit for that,
code_language.skript:
function formatseconds(n: number) :: timespan:
    set {_a} to "%{_n}% seconds" parsed as timespan
    set {_a} to "%{_a}%"
    replace all " seconds" or " second" with "sec" in {_a}
    replace all " minutes" or " minute" with "min" in {_a}
    replace all " hours" or " hour" with "h" in {_a}
    replace all " days" or " day" with "d" in {_a}
    return {_a}
 
Use @EWS's snippit for that,
code_language.skript:
function formatseconds(n: number) :: timespan:
    set {_a} to "%{_n}% seconds" parsed as timespan
    set {_a} to "%{_a}%"
    replace all " seconds" or " second" with "sec" in {_a}
    replace all " minutes" or " minute" with "min" in {_a}
    replace all " hours" or " hour" with "h" in {_a}
    replace all " days" or " day" with "d" in {_a}
    return {_a}
As i said in my post i already know about this, yet it's inconsistent very rarely displays the seconds and does not actually calculate times down to the decimals. Rounds down instead of up ect. This might be my skript version though if this is working for you i guess.
 
usually, the "difference between {_Var} and now" will give you a precise answer, in decimals if that is what you are looking for
 
usually, the "difference between {_Var} and now" will give you a precise answer, in decimals if that is what you are looking for
Yeah but timespan will only display Hours and minutes. It'll display excess days and hours as decimals but is not accurate
 
What do you mean "not accurate", like meaning that the timespans are rounded to a certain place? or what?
 
There is really simple solution for this:
code_language.skript:
set {_test} to "1200 ticks" parsed as timespan
What version of skript do you use? because timespan is only displayed as hours and minutes in mine?
[doublepost=1525225022,1525218390][/doublepost]Turns out skstuff's convert methods are broken, or some shit to do with timespans being broken as this should work i think?

command /testtime:
trigger:
set {test} to "86460 seconds" parsed as timespan
set {_GetDays} to {test} converted to days
Set {_GetMinutes} to "%{_GetDays}%" parsed as timespan converted to minutes
remove "%{_GetDays}% days" parsed as timespan from {_GetMinutes}
broadcast "Days %{_GetDays}%, Minutes %{_GetMinutes}%"

However just returns an internal error in chat and a bunch of errors in console to do with skstuff.
 
Status
Not open for further replies.