NetTalk Central
NetTalk Web Server => Web Server - Share Knowledge => Topic started by: DonRidley on June 27, 2019, 08:36:09 AM
-
I thought I would share these with anyone who is interested. Big thank you to Bruce for giving me a few clues. Also, thanks to Steve Parker for sharing some of his date/time methods with me (converted to JavaScript). I am no JS expert so feel free to modify or fix as needed.
function getClarionTime(clariontime) {
var d = new Date(),
clariontime = parseInt((d.getTime() - d.setHours(0,0,0,0)) / 10)
return clariontime;
}
function getClarionDate(clariondate) {
thisdate = new Date();
day = thisdate.getDay();
month = thisdate.getMonth()+1;
year = thisdate.getYear();
date = Date(year,month,day);
clariondate = parseInt(((Date.parse(date) / 86400) / 1000) + 61730);
return clariondate;
}
function createStarDate(date,time,stardate) {
//needs to be Clarion Date/Time
stardate = date + (time / 8640000)
return stardate;
}
function createRbnFromDateTime(date,time,rbn) {
//needs to be Clarion Date/Time
rbn = parseInt(time + (date * 8640000))
return rbn;
}
Don
-
Cool work Don.
This can be simplified down just a bit though, with the following;
I've also allowed for the return value to be in both UTC or Local time, whichever you need.
// returns date in Clarion Date format. Default is local time (of the browser), pass 1 in parameter to get utc time.
function clarionToday(utc){
time = Date.now()/10;
if (!utc){
d = new Date();
time -= d.getTimezoneOffset()*6000
}
return (parseInt(time / 8640000) + 61730)
}
// returns time in Clarion time format. Default is local time (of the browser), pass 1 in parameter to get utc time.
function clarionClock(utc){
time = Date.now()/10;
if (!utc){
d = new Date();
time -= d.getTimezoneOffset()*6000
}
return (parseInt(1+(time % 8640000)))
}
I've added these to the next build (in netweb.js). So you can cut & paste them into your netweb.js now if you want to use them.
cheers
Bruce
-
Thank you for adding those (and cleaning them up a little). Netweb.js is a pretty nice repository of JS tools.
Don