The following warnings occurred:
Warning [2] Use of undefined constant SAPI_NAME - assumed 'SAPI_NAME' (this will throw an Error in a future version of PHP) - Line: 3388 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3388 errorHandler->error
/showthread.php 116 build_archive_link
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/inc/functions.php 3324 build_forum_breadcrumb
/showthread.php 195 build_forum_breadcrumb
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/showthread.php 195 build_forum_breadcrumb






Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Time Conversion
Author Message
mlyon83
Apprentice
*

Posts: 44
Likes Given: 0
Likes Received: 0 in 0 posts
Joined: Apr 2013
Reputation: 0



Post: #1
Time Conversion
Does anyone have or want to write a function to convert seconds from a .TAG variable into Weeks, Days, Hours, Minutes, and Seconds?

It would say something like:

SRC.SYSMESSAGE @00 3 Weeks, 14 days, 19 Hours, 41 Minutes, and 12 Seconds. ///Conversion drawn from TAG value in seconds.
05-17-2013 02:43 AM
Find all posts by this user Like Post Quote this message in a reply
Mordaunt
Super Moderator
****

Posts: 1,237
Likes Given: 26
Likes Received: 55 in 43 posts
Joined: Mar 2012
Reputation: 35



Post: #2
RE: Time Conversion
It's just simple math....

TAG = secs

/60 = mins
/60/60 = hours
/60/60/24 = days
/60/60/24/7 = weeks

[Image: 2nis46r.jpg]
05-17-2013 04:53 AM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
mlyon83
Apprentice
*

Posts: 44
Likes Given: 0
Likes Received: 0 in 0 posts
Joined: Apr 2013
Reputation: 0



Post: #3
RE: Time Conversion
(05-17-2013 04:53 AM)Mordaunt Wrote:  It's just simple math....

TAG = secs

/60 = mins
/60/60 = hours
/60/60/24 = days
/60/60/24/7 = weeks

Mordaunt, I'm aware, but I'm horrible at math. Thanks for the numbers.
05-17-2013 05:25 AM
Find all posts by this user Like Post Quote this message in a reply
Gil Amarth
Journeyman
*

Posts: 189
Likes Given: 2
Likes Received: 1 in 1 posts
Joined: May 2012
Reputation: 0



Post: #4
RE: Time Conversion
It´s a bad thing to be a scripter bad in maths. xD

If you don´t mind in spanish:

Code:
[FUNCTION F_TIEMPO_FORMATO]

LOCAL.DIAS = <ARGS>/86400
LOCAL.RESTO = <F_DIVISION_RESTO <ARGS>,86400>
LOCAL.HORAS = <LOCAL.RESTO>/3600
LOCAL.RESTO = <F_DIVISION_RESTO <LOCAL.RESTO>,3600>
LOCAL.MINUTOS = <LOCAL.RESTO>/60
LOCAL.RESTO = <F_DIVISION_RESTO <LOCAL.RESTO>,60>    // Son los segundos

RETURN <dLOCAL.DIAS>,<dLOCAL.HORAS>,<dLOCAL.MINUTOS>,<dLOCAL.RESTO>

Code:
[FUNCTION f_division_resto]    // (DIVIDENDO, DIVISOR); Devuelve (RESTO)

LOCAL.NUMERO_VUELTAS = <ARGV[0]> / <ARGV[1]>
LOCAL.REDUCIDO = <LOCAL.NUMERO_VUELTAS> * <ARGV[1]>
LOCAL.VUELTAS_RESTO = <EVAL <ARGV[0]> - <LOCAL.REDUCIDO>>
RETURN <LOCAL.VUELTAS_RESTO>

It returns only days, hours, minutes and seconds, but you can tweak it to give you weeks and months, if you want.
05-17-2013 06:26 PM
Find all posts by this user Like Post Quote this message in a reply
mlyon83
Apprentice
*

Posts: 44
Likes Given: 0
Likes Received: 0 in 0 posts
Joined: Apr 2013
Reputation: 0



Post: #5
RE: Time Conversion
(05-17-2013 06:26 PM)Gil Amarth Wrote:  It´s a bad thing to be a scripter bad in maths. xD

If you don´t mind in spanish:

Code:
[FUNCTION F_TIEMPO_FORMATO]

LOCAL.DIAS = <ARGS>/86400
LOCAL.RESTO = <F_DIVISION_RESTO <ARGS>,86400>
LOCAL.HORAS = <LOCAL.RESTO>/3600
LOCAL.RESTO = <F_DIVISION_RESTO <LOCAL.RESTO>,3600>
LOCAL.MINUTOS = <LOCAL.RESTO>/60
LOCAL.RESTO = <F_DIVISION_RESTO <LOCAL.RESTO>,60>    // Son los segundos

RETURN <dLOCAL.DIAS>,<dLOCAL.HORAS>,<dLOCAL.MINUTOS>,<dLOCAL.RESTO>

Code:
[FUNCTION f_division_resto]    // (DIVIDENDO, DIVISOR); Devuelve (RESTO)

LOCAL.NUMERO_VUELTAS = <ARGV[0]> / <ARGV[1]>
LOCAL.REDUCIDO = <LOCAL.NUMERO_VUELTAS> * <ARGV[1]>
LOCAL.VUELTAS_RESTO = <EVAL <ARGV[0]> - <LOCAL.REDUCIDO>>
RETURN <LOCAL.VUELTAS_RESTO>

It returns only days, hours, minutes and seconds, but you can tweak it to give you weeks and months, if you want.

Wow, thank you much. Good thing I never got started on this myself. I'll run it through Google Translator.
05-18-2013 12:22 AM
Find all posts by this user Like Post Quote this message in a reply
mlyon83
Apprentice
*

Posts: 44
Likes Given: 0
Likes Received: 0 in 0 posts
Joined: Apr 2013
Reputation: 0



Post: #6
RE: Time Conversion
Now if you can just define the following, I'll be set:

- DIAS
- RESTO
- HORAS
- NUMERO_VUELTAS
- REDUCIDO
- VUELTAS_RESTO

rofl ;X
05-18-2013 01:55 AM
Find all posts by this user Like Post Quote this message in a reply
Gil Amarth
Journeyman
*

Posts: 189
Likes Given: 2
Likes Received: 1 in 1 posts
Joined: May 2012
Reputation: 0



Post: #7
RE: Time Conversion
The script is very simple, 1 day it´s 86400 seconds, so you have to divide the the total amount of seconds to how many seconds a day has.

Then you have to calculate the rest of the division, f_division_resto does that. It´s only maths.
With the rest you repeat the operation, 1 hour has 3600 seconds, and repeat.
If you want months, and weeks.

Code:
[FUNCTION F_FORMAT_TIME]

LOCAL.MONTHS = <ARGS>/2592000    // Months of 30 days
LOCAL.REST = <F_DIVISION_REST <ARGS>,2592000>
LOCAL.WEEKS = <LOCAL.REST>/604800
LOCAL.REST = <F_DIVISION_REST <LOCAL.REST>,604800>
LOCAL.DAYS = <LOCAL.REST>/86400
LOCAL.REST = <F_DIVISION_REST <LOCAL.REST>,86400>
LOCAL.HOURS = <LOCAL.REST>/3600
LOCAL.REST = <F_DIVISION_REST <LOCAL.REST>,3600>
LOCAL.MINUTES = <LOCAL.REST>/60
LOCAL.REST = <F_DIVISION_REST <LOCAL.REST>,60>    // Seconds

SYSMESSAGE @00 <dLOCAL.MONTHS> Months, <dLOCAL.WEEKS> Weeks, <dLOCAL.DAYS> Days, <dLOCAL.HOURS> Hours, <dLOCAL.MINUTES> Minutes, <dLOCAL.REST> seconds

Code:
[FUNCTION f_division_rest]    // (DIVIDEND, DIVISOR); Returns (REST)

LOCAL.LOOPS = <ARGV[0]> / <ARGV[1]>
LOCAL.ELAPSED = <LOCAL.LOOPS> * <ARGV[1]>
LOCAL.REST = <EVAL <ARGV[0]> - <LOCAL.ELAPSED>>
RETURN <LOCAL.REST>

Then, you can use F_FORMAT_TIME <TAG.TIME>, and voilá.
(This post was last modified: 05-18-2013 05:55 AM by Gil Amarth.)
05-18-2013 05:51 AM
Find all posts by this user Like Post Quote this message in a reply
Rizz
Master
**

Posts: 396
Likes Given: 21
Likes Received: 14 in 9 posts
Joined: Oct 2012
Reputation: 0



Post: #8
RE: Time Conversion
You should use the Julian Date time format, it's the best format to manage time bcuz you can literally sum and subtract a date (like 18/05/2013 19:31) and get the right result.
05-19-2013 03:31 AM
Find all posts by this user Like Post Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)