Is it possible to set up a clock trigger in Google Apps to send spreadsheet hourly? - triggers

I have a spreadsheet that logs incoming answered and missed calls in Google Drive.
It is currently set to send an email every hour between 10am and 7pm.
Ideally I would like it to not send the email during the weekend.
Setting up each hour Monday to Friday uses too many triggers.
Is there a way to construct a trigger that will send an email every hour (10am to 7pm) only Monday to Friday?
I've read the documentation at Google and a few (unrelated as it turns out) examples on here and I am stumped!
I tried putting a load of trigger conditions together:
function autoSendHourly() {
ScriptApp.newTrigger("hourlyUpdate()")
.timeBased()
.onWeekDay(ScriptApp.WeekDay.MONDAY)
.onWeekDay(ScriptApp.WeekDay.TUESDAY)
.onWeekDay(ScriptApp.WeekDay.WEDNESDAY)
.onWeekDay(ScriptApp.WeekDay.THURSDAY)
.onWeekDay(ScriptApp.WeekDay.FRIDAY)
.atHour(10)
.atHour(11)
.atHour(12)
.atHour(13)
.atHour(14)
.atHour(15)
.atHour(16)
.atHour(17)
.atHour(18)
.atHour(19)
.create();
}
I wasn't entirely surprised that it didn't work, but I was mildly surprised that it threw up no errors.
Any help (including "you're mad it can't be done") would be greatly appreciated.

The simplest thing to do is use the create trigger like you did but for every hour every day and then in you handler function add a small piece of code that will return if day and time don't meet specific conditions like explained in this (old) post.
the code may look like something like this :
function officeHours(){
var nowH=new Date().getHours();
var nowD=new Date().getDay();
Logger.log('day : '+nowD+' Hours : '+nowH)
if(nowH>17||nowH<8||nowD==6||nowD==0){return}
Browser.msgBox('time to work !');//normally your real function should begin here...
}

I haven't messed around with java in awhile but this article might help.
Android: how to get the current day of the week (Monday, etc...) in the user's language?
If it was me, I would get the day of the week and check it in a switch. Then if it matches a week day call a function to check the time between 10am and 7pm.
Best of luck.

Related

How can I calculate business/SLA hours with iterating over each second?

Before I spend a lot of time writing the only solution I can think of I was wondering if I'm doing it an inefficient way.
Once a support ticket is closed, a script is triggered, the script is passed an array of 'status-change-events' that happened from call open to close. So you might have 5 changes: new, open, active, stalled, resolved. Each one of these events has a timestamp associated with it.
What I need to do is calculate how much time the call was with us (new, open, active) and how much time it was with the customer (stalled). I also need to figure out how much of the 'us' time was within core hours 08:00 - 18:00 (and how many were non-core), and weekends/bank holidays count towards non-core hours.
My current idea is to for each status change, iterate over every second that occurred and check for core/non_core, and log it.
Here's some pseudo code:
time_since_last = ticket->creation_date
foreach events as event {
time_now = time_since_last
while (time_now < ticket->event_date) {
if ticket->status = stalled {
customer_fault_stalled++
} else {
work out if it was our fault or not
add to the appropriate counter etc
}
time_now++
}
}
Apologies if it's a little unclear, it's a fairly longwinded problem. Also I'm aware this may be slightly off of SO question guidelines, but I can't think of a better way of wording it and I need some advice before I spend days writing it this way.
I think you have the right idea, but recalculating the status of every ticket for every second of elapsed time will take a lot processing, and nothing will have changed for the vast majority of those one-second intervals
The way event simulations work, and the way I think you should write your application, is to create a list of all events where the status might change. So you will want to include all of the status change events for every ticket as well as the start and end of core time on all non-bank-holiday weekdays
That list of events is sorted by timestamp, after which you can just process each event as if your per-second counter has reached that time. The difference is that you no longer have to count through the many intervening seconds where nothing changes, and you should end up with a much more efficient application
I hope that's clear. You may find it easier to process each ticket separately, but the maximum gain will be achieved by processing all tickets simultaneously. You will still have a sorted sequence of events to process, but you will avoid having to reprocess the same core time start and end events over and over again
One more thing I noticed is that you can probably ignore any open status change events. I would guess that tickets either go from new to open and then active, or straight from new to resolved. So a switch between with your company and with the customer will never be made at an open event, and so they can be ignored. Please check this as I am only speaking from my intuition, and clearly know nothing about how your ticketing system has been designed
I would not iterate over the seconds. Depending on the cost of your calculations that could be quite costly. It would be better to calculate the borders between core/outside core.
use strict;
use warnings;
my $customer_time;
my $our_time_outside;
my $our_time_core;
foreach my $event ($ticket->events) {
my $current_ts = $event->start_ts;
while ($current_ts < $event->end_ts) {
if ($event->status eq 'stalled') {
$customer_time += $event->end_ts - $current_ts;
$current_ts = $event->end_ts;
}
elsif (is_core_hours($current_ts)) {
my $next_ts = min(end_of_core_hours($current_ts), $event->end_ts);
$our_time_core += $next_ts - $current_ts;
$current_ts = $next_ts;
}
else {
my $next_ts = min(start_of_core_hours($current_ts), $event->end_ts);
$our_time_outside += $next_ts - $current_ts;
$current_ts = $next_ts;
}
}
}
I can't see why you'd want to iterate over every second. That seems very wasteful.
Get a list of all of the events for a given ticket.
Add to the list any boundaries between core and non-core times.
Sort this list into chronological order.
For each consecutive pair of events in the list, subtract the later from the earlier to get a duration.
Add that duration to the appropriate bucket.
And the usual caveats for dealing with dates and times apply here:
Use a library (I recommend DateTime together with DateTime::Duration)
Convert all of your timestamps to UTC as soon as you get them. Only convert back to local time just before displaying them to the user.

Calculating Seconds Until a Given Date and Time in Joda Time

I am trying to use the Joda Time library to help me schedule sending some messages to an Actor in Akka.
I would like to schedule sending emails every day at 8:30 AM. To do this, I have to tell the scheduler how many seconds (or milliseconds) to wait until the next message is sent.
I would like to account for daylight savings (to make sure it always fires around 8:30, and not 7:30 or 9:30) so I will use LocalDate and LocalTime.
So, basically, I have:
targetDate = LocalDate.now().plusDays(1) and targetTime = new LocalTime(8, 30)
and
rightNow = LocalDateTime.now()
I was wondering what is the best way to compose a targetDateTime based on targetDate and targetTime so I can use it to compute the time difference with rightNow
I know I can create a new LocalDateTime extracting all the values for the constructor from my targetDate and targetTime but: is there a more elegant way?
So far, I have settled for:
targetDateTime = targetDate.toLocalDateTime(targetTime)
secondsToWait = Seconds.secondsBetween(rightNow, targetDateTime)
Getting targetDateTime is easy if you have the targetDate and targetTime (as given in your question) :
targetDateTime = targetDate.toDateTime(targetTime);
Getting the seconds of the Duration between now and targetDateTime:
new Duration(new DateTime(), targetDateTime).getStandardSeconds();
The method is called standard seconds because it assumes every second to be a standard second of 1000 milliseconds. As its javadoc says, currently all Chronologies only have standard seconds.
But you can also simply use milliseconds (no conversion assumptions needed) :
new Duration(new DateTime(), targetDateTime).getMillis();
Disclaimer : I only just saw this was a scala question, so you may have to correct for any syntax differences, since I'm not versed in scala.

How To set Custom repeat interval For Nslocal Notification.....?

i am New to iphone Development .I Am Trying To Use NslocalNotification In My Project I Need To Give Remeinder For Every 2Hours or For Every Two Days Or For Every Two Months Etc..Currently I am Using NslocalNotification Repeat Interval .But Its Working For Only Every Minute For Every Hour using Nscalender ....
NSString *InterVal=[freQuencyArr objectAtIndex:index-2];
NSString *InterValType=[freQuencyArr objectAtIndex:index-1];
if(![InterVal isEqualToString:#"Every"])
{
result=[InterVal intValue];
}else
result=1;
if([InterValType isEqualToString:#"Day"]){
notification.repeatInterval= NSDayCalendarUnit;
}else if([InterValType isEqualToString:#"Week"]){
notification.repeatInterval= NSWeekCalendarUnit;
}
else if([InterValType isEqualToString:#"Month"]){
notification.repeatInterval= NSMonthCalendarUnit;
}else if([InterValType isEqualToString:#"days"]){
notification.repeatInterval=result*24*60*60;
}
here If result is 2 depend Up on IntervalType I Need Notification
its Not Working With Me
if([InterValType isEqualToString:#"days"]){
notification.repeatInterval=result*24*60*60;
}
#Srinivas:
If you look at the link I have posted in this answer, You will come to know that I have tried every possible solution here to try and do what you want currently.
I had tried all this to implement it in my app, but this doesn't work.
I am afraid to say this but this is not possible. It only allows the unit NSCalendarUnit objects to be set as a repeat interval.
I invested almost 2 months (I asked the question in Dec 2010 and answered it myself in February 2011) to try and implement every possible solution available on internet through different articles and different forums but none did help.
Check out my link and lookout for all the answers if something is useful to you.
How to set Local Notification repeat interval to custom time interval?
Really Hope that this helps you.
The repeatInterval property of a UILocalNotification cannot be used to repeat less than every one calendar unit, i.e. every day, every week, every month, etc.
Instead, you will have to schedule multiple notifications to achieve the desired effect, setting the fireDate property accordingly.
As lemnar says you are unable to use repeatInterval to repeat in a frequency different from the calendar units Apple provided. So, the code below:
if([InterValType isEqualToString:#"days"]){
notification.repeatInterval=result*24*60*60;
}
Will not do anything. I am also using repeat notifications in an app that I have built and the way I've gotten around this is by creating multiple notifications each repeating to give the "desired" repeat frequency. As an example, if I want to repeat "every 2 days", I can't do this using repeatInterval. However, I have a "scheduling function" in my app that creates multiple individual notifications to achieve this. I do this going out an arbitrary length of time (in my case, one week). So in the example above, when the user specifies that he / she needs a notification every two days from today, I create 3 notifications (one each for day 3, 5, and 7).
For repeating at a frequency less than a calendar unit, things are a little easier. Say I need to repeat every 12 hours (at 6AM and 6PM). Then, I would create 2 notifications (one for 6AM and another for 6PM). I would then set the repeatInterval for each of these notifications to NSDayCalendarUnit. This way I have created a set of notifications that repeat every 12 hours.
When my app loads, I go out another 7 days and recreate notifications as needed. Not the most elegant solution, but this was the best way I could think of getting around the repeatInterval limitation.

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date rolls over from December 26th to December 27th, the year changes to 2010.
I even rolled it forward to 2011... and it changes when December 25th changes to the 26th.... but wait... in 2012, it correctly rolls over on December 31 - January 1... and then its back to 29th-30th in 2013. Is there some kind of astronomical phenomenon I am not aware of going on or does Apple run on some crazy Heechee calendar I don't know of? The calendar app works correctly...
The most likely explanation is I am missing something so obvious that I will slap myself when I realize it. But hey, I haven't slept in... wow I don't remember if its been two days or three. Take pity and help me out here.
UPDATE: So maybe it wasn't something simple. Still looking for an answer here! Am I really the only person who has experienced this?? I'll bet when the end of December rolls around, more people will hit the same roadblock.
UPDATE2: Anyone? Still looking, still not finding...
UPDATE3: Still haven't found a solution. Come on! This is an interesting puzzle!
UPDATE4: Still no answer found. I have submitted the app and it is now in the appstore. Would still like to see this problem solved so I can update the app.
There may be this problem, that when you are on the last week of the month and the week has fewer than 7 days left in current month, then perhaps the API treated the week as the first week of the next month. Since december of 2012 has already 7 days in its last week there is no problem in that month.
I was getting the same problem here, and I solved it.
- (int) currentWeekOfMonth
{
return CFCalendarGetOrdinalityOfUnit (
CFCalendarCopyCurrent(),
kCFCalendarUnitWeek,
kCFCalendarUnitMonth,
[self absoluteTime]);
}
my requirement is to show week number and for this i calculate the week number of first week of month and the add this to the total number of week in month.
int currentWeekNumberInYear = [_calendarInfo currentWeekOfYear];
int currentWeekNumberInMonth = [_calendarInfo currentWeekOfMonth];
currentWeekNumberInYear = currentWeekNumberInYear-currentWeekNumberInMonth +1;
currentWeekNumberInYear = currentWeekNumberInYear<0 ? (NSInteger)[_calendarInfo weeksInMonth] ==5 ?49:48 : currentWeekNumberInYear;
I hope it will be useful to you.
Turns out its the Date format string used to set up the NSDateFormatter that was causing this for me.
"yyyy" corresponds to the 4-digit year, while YYYY corresponds to the year starting from the Sunday of the 1st week of year. Why anyone would want this is anyone's guess, and it would really help if Apple provided a link to their list of format specifiers, but there you go.
Just make sure your format string has the year component in lowercase and it should be sorted.
This post on TUAW describes a similar problem in PhotoBooth on Mac OS X:
http://www.tuaw.com/2009/12/29/beware-photo-booth-time-stamps-its-a-bug-not-a-feature/
One commenter agrees with vikas that it's an end-of-week issue.

Count-Up Timer Required, iPhone Programming

I am new to iPhone programming so am hoping someone can help me out here. I have searched the web, but can only find information on count down timers.
What I am looking to do is start a count up timer when a button is pressed and then stop it when a certain value drops by, say 5, and finally display that time. I can display values on screen once I have them, but getting the time in the first place is proving difficult for me.
I apologize if this is a simple question, but I look forward to reading your responses.
Thanks in advance,
stu
NSDate will provide the current date. You can use - (NSTimeInterval)timeIntervalSinceNow
to get the time since the first call and now.
There's no difference between an up-counter and down-counter. Just change the order of your subtraction.
UpcounterElapsedTime = UpcounterCurrentTime - UpcounterStartTime;
DowncounterElapsedTime = DownCounterStartTime - DownCounterCurrentTime;