### Author Topic: Juliandate with hours/seconds  (Read 6209 times)

0 Members and 1 Guest are viewing this topic.

#### TTB

• Lord
• Posts: 436
• Karma: +17/-1
##### Juliandate with hours/seconds
« on: 07 February, 2007, 10:44:55 »
Hi,

There is a julianday / juliandate at this moment, and gives a exact number on each day. Is there also a function with a specific number on each second?

Gr.
TTB

(? ?.??.-> Admin @ Surfnet hubs <-.??.???)

#### PtokaX forum

##### Juliandate with hours/seconds
« on: 07 February, 2007, 10:44:55 »

#### Leun

• Scripter
• Fulll Member
• Posts: 64
• Karma: +7/-0
##### Re: Juliandate with hours/seconds
« Reply #1 on: 07 February, 2007, 13:44:32 »

Modded the script from VidFamne a bit (upper script), now there's a function for seconds

Code: [Select]
`--VidFamne--(Modified Julian "minute" number. This restricts the algorithm to 1900 Mar 01 until 2100 Feb 28)-- Julian to minutesJmn = function() local D = tonumber(os.date("%d")) local H = tonumber(os.date("%H")) local minutE = tonumber(os.date("%M")) local Y = tonumber(os.date("%Y")) local M = tonumber(os.date("%m")) if M <= 2 then M = M + 12 Y=Y-1 end mn = 1440*(math.floor(Y*365,25) + math.floor((M+1)*30,6) + D -428) + H*60 + minutE return mnend--VidFamne--(Modified Julian "minute" number. This restricts the algorithm to 1900 Mar 01 until 2100 Feb 28)-- Julian to secondsJsn = function() local D = tonumber(os.date("%d")) local H = tonumber(os.date("%H")) local minutE = tonumber(os.date("%M")) local secondS = tonumber(os.date("%S")) local Y = tonumber(os.date("%Y")) local M = tonumber(os.date("%m")) SendToAll(M) if M <= 2 then M = M + 12 Y=Y-1 end mn = 1440*(math.floor(Y*365,25) + math.floor((M+1)*30,6) + D -428) + H*3600 + minutE*60 + secondS return mnend `
Maby anyone has an other function, but thisone works :-)

Greetz,

#### bastya_elvtars

• Forum God
• Posts: 3 744
• Karma: +173/-7
• The rock n' roll doctor
##### Re: Juliandate with hours/seconds
« Reply #2 on: 07 February, 2007, 14:02:01 »
Code: Lua
1. function JulianDate(DAY, MONTH, YEAR, HOUR, MINUTE, SECOND) -- Written by RabidWombat.
2. -- HOUR is 24hr format.
3.   local jy, ja, jm;
4.   assert(YEAR ~= 0);
5.   assert(YEAR ~= 1582 or MONTH ~= 10 or DAY < 4 or DAY > 15);
6.   --The dates 5 through 14 October, 1582, do not exist in the Gregorian system!
7.   if(YEAR < 0 ) then
8.     YEAR = YEAR + 1;
9.   end
10.   if( MONTH > 2) then
11.     jy = YEAR;
12.     jm = MONTH + 1;
13.   else
14.     jy = YEAR - 1;
15.     jm = MONTH + 13;
16.   end
17.   local intgr = math.floor( math.floor(365.25*jy) + math.floor(30.6001*jm) + DAY + 1720995 );
18.   --check for switch to Gregorian calendar
19.   local gregcal = 15 + 31*( 10 + 12*1582 );
20.   if(DAY + 31*(MONTH + 12*YEAR) >= gregcal ) then
21.     ja = math.floor(0.01*jy);
22.     intgr = intgr + 2 - ja + math.floor(0.25*ja);
23.   end
24.   --correct for half-day offset
25.   local dayfrac = HOUR / 24 - 0.5;
26.   if( dayfrac < 0.0 ) then
27.     dayfrac = dayfrac + 1.0;
28.     intgr = intgr - 1;
29.   end
30.   --now set the fraction of a day
31.   local frac = dayfrac + (MINUTE + SECOND/60.0)/60.0/24.0;
32.   --round to nearest second
33.   local jd0 = (intgr + frac)*100000;
34.   local  jd  = math.floor(jd0);
35.   if( jd0 - jd > 0.5 ) then jd = jd + 1 end
36.   return jd/100000;
37. end
38.
39. function frac(num) -- returns fraction of a number (RabidWombat)
40.   return num - math.floor(num);
41. end

Could be optimized more for 5.1, but haven't yet had time.
Everything could have been anything else and it would have just as much meaning.

#### Leun

• Scripter
• Fulll Member
• Posts: 64
• Karma: +7/-0
##### Re: Juliandate with hours/seconds
« Reply #3 on: 07 February, 2007, 14:09:17 »
lol thats much better ;D

#### Yahoo

• Triple Ace
• Posts: 225
• Karma: +32/-14
• People Say "I Dont Know English"
##### Re: Juliandate with hours/seconds
« Reply #4 on: 07 February, 2007, 14:16:38 »
i am getting the error for the script posted by bastya_elvtars
[18:41] Syntax \scripts\julian.lua:44: '=' expected near 'be'
"BoRN FIGhTEr"

#### TTB

• Lord
• Posts: 436
• Karma: +17/-1
##### Re: Juliandate with hours/seconds
« Reply #5 on: 07 February, 2007, 14:41:45 »
Thanx bastya... I think I can work with this.
TTB

(? ?.??.-> Admin @ Surfnet hubs <-.??.???)

#### bastya_elvtars

• Forum God
• Posts: 3 744
• Karma: +173/-7
• The rock n' roll doctor
##### Re: Juliandate with hours/seconds
« Reply #6 on: 07 February, 2007, 14:42:29 »
i am getting the error for the script posted by bastya_elvtars
[18:41] Syntax \scripts\julian.lua:44: '=' expected near 'be'

Try not copying the last line of my post, since it's a comment.
Everything could have been anything else and it would have just as much meaning.

#### Psycho_Chihuahua

• Systemspecialist IT
• Emperor
• Posts: 1 054
• Karma: +112/-1
• I am wherever i want to be
##### Re: Juliandate with hours/seconds
« Reply #7 on: 07 February, 2007, 15:13:21 »
Try not copying the last line of my post, since it's a comment.

That should be obvious though
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

#### plop

• Forum God
• Posts: 2 464
• Karma: +37/-0
##### Re: Juliandate with hours/seconds
« Reply #8 on: 07 February, 2007, 20:32:43 »
why so complex when it's build into lua from version 5.0 and up?
Code: [Select]
`--code snipe from a.i. v2 (bsd license) JulianDate = function(tTime) if not tTime then local tTime = os.date("*t") return os.time({year = tTime.year, month = tTime.month, day = tTime.day, hour = tTime.hour, min = tTime.min, sec = tTime.sec} ) end return os.time({year = tTime.year, month = tTime.month, day = tTime.day, hour = tTime.hour, min = tTime.min, sec = tTime.sec} ) end, CedianDateTable = function(iJdate) return os.date("*t", iJdate) end, CedianDateString = function(iJdate) return os.date("%c", iJdate) end, JulianDiff = function(iThen, iNow) return os.difftime( (iNow or tMain.JulianDate()) , iThen) end,`1 note, this isn't compatible with the lua versions posted above as it uses the unix style.
doesn't start from 0:00.00 01-01-0000 but from 00:00.00 01-01-1970.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

#### speedX

• Lord
• Posts: 437
• Karma: +59/-19
##### Re: Juliandate with hours/seconds
« Reply #9 on: 07 February, 2007, 21:00:37 »
Could any please tel me how this works??
Thanking You,

speedX

#### plop

• Forum God
• Posts: 2 464
• Karma: +37/-0
##### Re: Juliandate with hours/seconds
« Reply #10 on: 07 February, 2007, 21:23:52 »
Could any please tel me how this works??

click

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

#### bastya_elvtars

• Forum God
• Posts: 3 744
• Karma: +173/-7
• The rock n' roll doctor
##### Re: Juliandate with hours/seconds
« Reply #11 on: 07 February, 2007, 22:27:33 »
why so complex when it's build into lua from version 5.0 and up?

Because I did not know anything about this before, simply overlooked in the manual. Thanks for the snippet.
Moved to howtos.
Everything could have been anything else and it would have just as much meaning.

#### PtokaX forum

##### Re: Juliandate with hours/seconds
« Reply #11 on: 07 February, 2007, 22:27:33 »