Juliandate with hours/seconds
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Juliandate with hours/seconds

Started by TTB, 07 February, 2007, 10:44:55

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TTB

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 <-.??.???)

Leun


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

--VidFamne
--(Modified Julian "minute" number. This restricts the algorithm to 1900 Mar 01 until 2100 Feb 28)
-- Julian to minutes
Jmn = 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 mn
end



--VidFamne
--(Modified Julian "minute" number. This restricts the algorithm to 1900 Mar 01 until 2100 Feb 28)
-- Julian to seconds
Jsn = 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 mn
end


Maby anyone has an other function, but thisone works :-)

Greetz,

bastya_elvtars

Code: lua
function JulianDate(DAY, MONTH, YEAR, HOUR, MINUTE, SECOND) -- Written by RabidWombat.
-- HOUR is 24hr format.
  local jy, ja, jm;
  assert(YEAR ~= 0);
  assert(YEAR ~= 1582 or MONTH ~= 10 or DAY < 4 or DAY > 15);
  --The dates 5 through 14 October, 1582, do not exist in the Gregorian system!
  if(YEAR < 0 ) then
    YEAR = YEAR + 1;
  end
  if( MONTH > 2) then
    jy = YEAR;
    jm = MONTH + 1;
  else
    jy = YEAR - 1;
    jm = MONTH + 13;
  end
  local intgr = math.floor( math.floor(365.25*jy) + math.floor(30.6001*jm) + DAY + 1720995 );
  --check for switch to Gregorian calendar
  local gregcal = 15 + 31*( 10 + 12*1582 );
  if(DAY + 31*(MONTH + 12*YEAR) >= gregcal ) then
    ja = math.floor(0.01*jy);
    intgr = intgr + 2 - ja + math.floor(0.25*ja);
  end
  --correct for half-day offset
  local dayfrac = HOUR / 24 - 0.5;
  if( dayfrac < 0.0 ) then
    dayfrac = dayfrac + 1.0;
    intgr = intgr - 1;
  end
  --now set the fraction of a day
  local frac = dayfrac + (MINUTE + SECOND/60.0)/60.0/24.0;
  --round to nearest second
  local jd0 = (intgr + frac)*100000;
  local  jd  = math.floor(jd0);
  if( jd0 - jd > 0.5 ) then jd = jd + 1 end
  return jd/100000;
end

function frac(num) -- returns fraction of a number (RabidWombat)
  return num - math.floor(num);
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


Yahoo

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

Thanx bastya... I think I can work with this.
TTB

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

bastya_elvtars

Quote from: Yahoo 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'

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

Quote from: bastya_elvtars on 07 February, 2007, 14:42:29
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

why so complex when it's build into lua from version 5.0 and up?
--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

Could any please tel me how this works??
Thanking You,

speedX

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

Quote from: plop on 07 February, 2007, 20:32:43
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.

SMF spam blocked by CleanTalk