I am using an onEdit trigger to trigger a Google Apps Script. Essentially, I am using the results of a Form to populate a calendar event. Once I've created the calendar event, I want to be able to keep it in sync with the form entry. So if someone edits the form data, I want to edit the calendar event. Unfortunately, since there is no getEventById storing the eventId is not enough.
I was thinking I might be able to use the event['oldValue'] which stores the event time to figure out when the event used to be (in case it changes) to get a list of events at that time which will allow me to iterate through a small number of events to find the calendar event.
Unfortunately, the date object comes out as a weird floating point number that I can't parse. e.g: 1/19/2016 20:00:00 comes out as 42388.791666666664 which I really don't understand.
I did have another thought, should I just use a regular HTTP get call to get the event I want? I'm not exactly sure how to do that from within a Google Apps Script
Maybe late, but you can see the answer here
var x = 42521.015713761575;
// seconds in day = 24 * 60 * 60 = 86400
var date = new Date(1899, 11, 30, 0, 0, x * 86400);
Related
At our office we check in by opening a webpage and clicking on a check-in button.The following function is called while clicking the button:
function checkInOutSubmit(thisController, thisAction, checkName){
var visitortime = new Date();
var visitortimezone = "GMT " + -visitortime.getTimezoneOffset() / 60;
var timeZone = jstz.determine_timezone();
var timeZoneName = timeZone.name();
var checkInCheckOut = checkName
jQuery.ajax({type:'POST',data:{checkInCheckOut:checkInCheckOut,currentController: thisController,currentAction: thisAction,timez:timeZoneName}, url:'/pms/attendanceForgot/checkInCheckOut',success:function(data,textStatus){jQuery('#successdiv').html(data);successCheckInOut();},error:function(XMLHttpRequest,textStatus,errorThrown){}});
}
But I want to put a old time when clicking on the button and not the current time.(If I reach click the button at 11:00am, I want to post 10:00am as my checkin time).
How can this be done?
There is not enough information here to answer your question.
All this code is doing is finding the current time zone, not the current time. It passes that to the server via an ajax request, which makes me think the time is generated server side. It's possible you could alter the logged time on the server by changing the timezone to an offset that would make it look like you are clocking in at the right time, but it would have to be some seriously deficient code on the server for that to work.
In almost all likelihood, the server is storing the time of the request in universal time as the clock in time and when you leave it's storing the time you leave in universal time as well. (think a point in time that isn't dependent on timezones) If your goal is get more hours, you'll just have to work later when you come in late. If you want it to look like you came in "on time", then changing the timezone might help until they notice that you've been there from 10am to 6pm but are only logging 7 hours.
I was using the following MySQL event to update the table with the (CURRENT_TIME)+5) every five min. however my plan is was to get the table updated with that time every full 5 min from current time:
e.g., on 12:05 it writes 12:10, on 12:10 it writes 12:15...
So I used to fire the below event at exactly 12:30:00 for example in order to get it accurate.
CREATE EVENT x_next
ON SCHEDULE EVERY 5 MINUTE
STARTS CURRENT_TIMESTAMP
DO
UPDATE data SET x_next= CONCAT(CONCAT(HOUR(CURRENT_TIME),':'),MINUTE(CURRENT_TIME)+5);
What I am looking now is to make it more accurate to make this event act like the following JSfiddle result where if the even started at any time it will update only on the next 5 min (snapped-to):
http://jsfiddle.net/v06jrobg/
Where the result should be what the event should update.
I am wondering if anyone had this experience before or any suggestions?
Try to define a start time instead of current_timestamp
CREATE EVENT x_next
ON SCHEDULE EVERY 5 MINUTE
STARTS '2014-10-08 12:00:00'
DO
UPDATE data SET x_next=
CONCAT(HOUR(DATE_ADD(Now(),INTERVAL +5 MINUTE)),':',
MINUTE(DATE_ADD(Now(),INTERVAL +5 MINUTE)));
This will start at 12:00:00 and execute every 5 minute.
I changed your update syntax a bit also. It makes sure that the hour is added with 5 minutes, in case at 16:55 , the next value is 17:00. I think this will give 17:0 and not 17:00, might have to fix a check for that. A bit hacky but it might do the trick?
I use this jquery plugin: livestamp.
If you know, tell please, how to show time (hours, minutes ago) only for the current day. After 24 hours on next day - to show label "yesterday" or simple date.
Thank you!
By default, I don't think livestamp can do this.
But, at the bottom of livestamp's examples, they have some code to animate the text when it changes by hooking into the change.livestamp event.
We can use moment.js to modify this code to do what you're asking.
$('#animation').on('change.livestamp', function(event, from, to) {
event.preventDefault(); // Stop the text from changing automatically
// Get the original timestamp out of the event
var originalTS = event.timeStamp;
// Make a new moment object to compare the timestamp to
var newDate = moment();
// Use moment's .diff method to get the ms difference between timestamps
var delta = newDate.diff(originalTS);
// If the difference is less than a day's worth of ms
if (delta < 86400000){
// Use formatted text provided by the change event
$(this).html(to);
}
else {
// Format the moment object with whatever moment format you want
$(this).html( newDate.format("dddd M/D/YYYY") );
}
}).livestamp();
I haven't used livestamp, but it seems to rely on moment existing for its formatting options, so this should just work.
Livestamp's source is super small, so consider hacking on it yourself if you have other stuff you want to be able to do.
I have a simple JavaScript chronograph that displays on a form field called "d2", it is used to check how long someone takes on doing a specific task:
var milisec=0
var seconds=0
var complemento1=""
document.form1.d2.value='00:00:00'
function display(){
if (milisec>=9){
milisec=0
seconds+=1
}
else{
milisec+=1
}
complemento1=complemento2=complemento3="";
if ((seconds%60)<10) complemento1="0";
if ((Math.floor(seconds/60)%60)<10) complemento2="0";
if ((Math.floor(seconds/3600))<10) complemento3="0";
document.form1.d2.value=complemento3+Math.floor(seconds/3600)+":"+complemento2+(Math.floor(seconds/60)%60)+":"+complemento1+(seconds%60)
setTimeout("display()",100)
}
The problem is that when the person opens a new tab / uses another program the timer stops, and then resumes when the window is focused again (Using Chrome). It has the weirdest behavior, because sometimes it works, sometimes it doesn't.
I saw many posts that needed a script to stop when not on focus, I want the exact opposite and searched for over an hour with no luck. Your help is greatly appreciated!
JavaScript timeouts are not guaranteed be executed at a specific time. For example if the thread is busy with something else at the time when the timer finishes, it will first finish what it is doing and then execute your timer.
Also your function does not take into account the time spend inside the display function, so a little delay will be added for each millisecond.
The correct way to implement a timer is using the system time.
So something like:
//Call at the beggining to save the start time
var start_time = new Date()
// Compute seconds (does not matter when/how often you call it.)
var milliseconds_since_start = new Date().valueOf() - start_time
The Date object can also format this period as a clock for you:
var m = new Date(milliseconds_since_start)
m.getMinutes()+":"+m.getSeconds()
I made a similar question few hours ago, but I think I asked a wrong question there. This is more exact one.
im using cURL on PHP and i want to use a site, but everytime i change my site, the browser posts a value x to server, and if you dont, you can't go to the site.
you can see that the x value changes all the time from the picture, its a FireFox Live HTTP headers addon, it shows what pages i visit with browser
i looked the source code and found out what is the x value, and it comes from javascript. can i get the value with cURL or some other way from the server?
date = new Date();
ms = (date.getHours() * 24 * 60 * 1000) + (date.getMinutes() * 60 * 1000) + (date.getSeconds() * 1000) + date.getMilliseconds();
so the main problem is that the x value changes all the time and it has to be exactly "right" value , even milliseconds must be correct. i tried finding the value myself with javascript and then putting it to php, but still does not work
The reason is simple, you mixed between $_POST and $_GET
Check your PHP make sure is refer/using $_GET['x']
All that javascript is doing is calculating the current time in milliseconds on the client and sending it to the server. You can calculate such a time in php trivially with $ms = time() * 1000;