FAQ Database Discussion Community


Change NSTimer interval after a certain number of fires

objective-c,cocoa-touch,nstimer,intervals
In the following code, the NSTimer interval is set at 1 second between each picture. My goal is to change the interval after the first two pictures, hello.png and bye.png, to 4 seconds. - (void)viewDidLoad { [super viewDidLoad]; NSArray *imageNames = @[@"hello.png",@"bye.png",@"helloagain.png",@"bye again"]; self.images = [[NSMutableArray alloc] init]; for (int...

PHP DateTime Interval errors

php,datetime,intervals,dateinterval
if (empty($krow['BUSSTRT'])){ $busts = $ts->add(new DateInterval('PT6i5s')); $busDate = $busts->format('m/d/Y H:i:s'); echo "busDate:".$busDate."<br>\n"; }else{ $busts = new DateTime($krow['BUSSTRT']); $busDate = $busts->format('m/d/Y H:i:s'); echo "busSTRT:".$busDate."<br>\n"; } if (empty($krow['LAMISTRT'])){ echo "lamistrt is empty::::"; $lamts = $busts->add(new DateInterval('PT11is')); $lamDate = $lamts->format('m/d/Y H:i:s'); echo "lamDate:".$lamDate."<br>\n"; }else{ $lamts = new...

SQL select all but exlude results when datetime is between midnight and 6am

mysql,datetime,intervals
I have a basic problem with an SQL query and I can't find the solution. I have a table where the first column is a epoch timestamp and a new entry is saved every 15min, and I want to select all the entires between two dates. Let's say a month....

For-loop to find values falling into a specified interval in Matlab

matlab,for-loop,matrix,indexing,intervals
In Matlab I have a matrix pvals where size(pvals) = 210 x 210. I want to "search" the matrix such that if any value in pvals is such that pvals < 2.7613 or pvals > 0.3621405 Then I want another matrix VALS to record that entry as 0. So that...

Finding All Intervals That Overlap a Point

c++,computational-geometry,intervals,skip-lists
Consider a large set of floating-point intervals in 1-dimension, e.g. [1.0, 2.5], 1.0 |---------------|2.5 [1.5, 3.6], 1.5|---------------------|3.6 ..... It is desired to find all intervals that contain a given point. For example given point = 1.2, algorithm should return the first interval, and if given point = 2.0, it should...

Add two hours to timestamp

sql,oracle,plsql,timestamp,intervals
I've got a trigger that has to set a timestamp to the current time plus two hours when the field is null before insert. One of the statements I tried so far is IF :new.time_to_live IS NULL THEN :new.time_to_live := sysdate + INTERVAL '0 02:00:00.0' HOUR TO MINUTE; END IF;...

Convert Date to interval string oracle

sql,oracle,intervals
I have the following validation: DATE1 + INTERVAL to_char(DATE2, 'HH24:MI:SS') HOUR TO SECOND > DATE3; But it keeps me saying that the operator is not valid. What am I doing wrong?...

Youtube iframe javascript, track percentage of video watched?

javascript,video,youtube,intervals,track
I am trying to get an accurate calculation of how much time a user has spent watching a video. The time they spent watching it should not include skipping forward or when the video is paused. The code I have now is giving me a different percentage each time (I'm...

Conflict with simulation cron

angularjs,cordova,time,intervals,ionic
Community, I have the following problem. I am running an action every certain stretch of time, for example, 1 minute. The function, if the device is locked continues to run normally but there comes a time (about 5 minutes) fails, no error or any type of log to run, to...

Postgresql complains when interval is result of string concatenation

postgresql,date,casting,intervals
Using this answer to convert a (date + interval) into a date. Only in my case the date and the interval are strings that are the result of slice&dice of other strings. The problem is that it works when I construct the string for the date but not for the...

Combinations of N Boost interval_set

c++,algorithm,boost,intervals,boost-icl
I have a service which has outages in 4 different locations. I am modeling each location outages into a Boost ICL interval_set. I want to know when at least N locations have an active outage. Therefore, following this answer, I have implemented a combination algorithm, so I can create combinations...

QSerialPort: how to adjust the emiting time of readysignal using number of bytes received

qt,serial-port,intervals,qtserialport
I am using Qserialport to receive a 7 byte data on every 10 ms. the baud rate is 115200. and i use signal(readyread) and slot(readLine in a separate function) method. the ready read signal is only emitted on every 16ms. but my device sends data at 10 ms interval. How...

Javascript Event Listener at Interval

javascript,intervals,event-listener
I'm listening for motion data on devices, using the ondevicemotion API. For example: window.ondevicemotion = function(event) { // do something with the event } I want to run this function when I call it; however, because it is based on an event, it triggers when the event does (which, depending...

Combine data into smaller discrete intervals

f#,mapping,intervals,discrete-mathematics
Suppose we have a pair of input arrays, or a list of (key, value) tuples if you prefer. What's an elegant and performant way to combine values that have indices falling in a certain interval? For example, if the interval (or 'bin') size is 10 then the values of all...

Getting error when using prepareStatement with interval in query

java,oracle,prepared-statement,intervals
When running this query SELECT SYSDATE + INTERVAL '7' DAY FROM DUAL; in a prepareStatement like this PreparedStatement ps = connection.prepareStatement("select sysdate + interval ? day from dual" ); ps.setString(1, "7"); ps.executeQuery(); It will throw an exception, that the syntax is not good, it clearly is, cuz i'm able to...

How many intervals are containing an another interval?

algorithm,optimization,intervals
There are given N intervals, with start and end points. How many pairs of these intervals exists, such that one interval is containing the another interval? For example, if the given intervals are: {2,3},{1,5},{0,10},{2,4} then we have 5 pairs: {0,10} contains {2,3} {0,10} contains {2,4} {0,10} contains {1,5} {1,5} contains...

setInterval not repeating

javascript,web,intervals
I'm trying to change the background each 4 seconds but it jumps directly to the second condition and doesn't change anymore. Why is this happening? var time = 1; var func = function () { 'use strict'; if (time === 1) { document.getElementById("top-background").style.backgroundColor = "#000"; time += 1; } if...

How to check if a number is in a interval

python,coding-style,range,intervals
Suppose I got: first_var = 1 second_var = 5 interval = 2 I want an interval from second_var like second_var ± interval (from 3 to 7). I wank to check if first_var is in that interval. So in this specific case I want False If first_var = 4, I want...

Run jQuery ajax in custom intervals

jquery,ajax,intervals
I have a jQuery ajax function. On page load, it should not be executed. Then after 5 minutes, it should be executed, and then 5 minutes later, it gets executed again and so on... Here is my code: jQuery(document).ready(function(){ jQuery.ajax({ url: "/wp-admin/admin-ajax.php", data : {action: "check_noti_log"}, context: this, success:function(data){ //...

Translation of interval

postgresql,datetime,translation,intervals,postgresql-8.4
There is maybe a way to translate automatically interval as it's shown by postgresql (e.g. "1330 days 10:54:54.266684") to other languages? For instance using locales, or other settings or I have to use replace, e.g. regexp_replace((now()-t.another_date)::text, 'day','dzień')?

Union and intersection of intervals

r,intervals
I have a group of intervals for different ids. For example: df <- data.frame(id=c(rep("a",4),rep("b",2),rep("c",3)), start=c(100,250,400,600,150,610,275,600,700), end=c(200,300,550,650,275,640,325,675,725)) The intervals of each id do not overlap but the intervals of the different ids may overlap. Here is a picture: plot(range(df[,c(2,3)]),c(1,nrow(df)),type="n",xlab="",ylab="",yaxt="n") for ( ii in 1:nrow(df) ) lines(c(df[ii,2],df[ii,3]),rep(nrow(df)-ii+1,2),col=as.numeric(df$id[ii]),lwd=2)...

jQuery - clearInterval seems not to work

jquery,if-statement,intervals,clearinterval
Long story short: If the interval count exceeds 5 the code should clear the interval, stopping it from executing the function every second. But this doesn't seem to work. HTML <div id='feedback'></div> JavaScript / jQuery window.intervalcount = 0; var interval = setInterval(function () { intervalcount += 1; $("#feedback").text(intervalcount); }, 1000);...

How to apply newly added object in array in ng-repeat interval?

javascript,angularjs,intervals
Assuming the following scenario: first click cont! button and then add!, How to apply in counting function newly pushed object in array, so that it would be displayed as last in ng-repeat? Updated working example: var app = angular.module('app', []); app.controller('homeCtrl', function($scope, $interval) { $scope.tabs = [{ name: "one", active:...

Increment minute to the nearest 15 minute interval

php,date,datetime,intervals
I think I am almost there - trying to get the current time then add an hour to it then output the options to 15 mins intervals - so if it is 14:12 the first available slot would be 14:15 and then every 15 mins till my end time $start...

Oracle SQL Query Where Timestamp is in Last 1 hour Using Systimestamp

sql,oracle,timestamp,intervals
Using oracle 11g I read another SO post where interval '1' hour should work the same way I expect it to, so I am wondering why I would get different results from these two queries and maybe help better understanding how the interval query works... The intention of these two...

JavaScript Calculate time difference in known intervals

javascript,date,datetime,time,intervals
I'm Struggling with calculation of date time objects :( We're getting three inputs from the user: 1. Start time of day 2. End time of day 3. Intervals between events (in minutes) My target goal is to calculate how many events I have every day from start time to end...

using intervals to assign categorical values

r,data.frame,dplyr,intervals
Take the following generic data A <- c(5,7,11,10,23,30,24,6) B <- c(1,2,3,1,2,3,1,2) C <- data.frame(A,B) and the following intervals library(intervals) interval1 <- Intervals( matrix( c( 5, 15, 15, 25, 25, 35, 35, 100 ), ncol = 2, byrow = TRUE ), closed = c( TRUE, FALSE ), type = "Z" )...

VB2010 Setting logarithmic scale intervals

vb.net,visual-studio-2010,charts,intervals
I'm developing a financial application in which I need to display data in a chart with a logarithmic scale on the Y axis. Everything works fine except for the intervals. With the following: chart.ChartAreas(0).AxisY.IsLogarithmic = True chart.ChartAreas(0).AxisY.LogarithmBase = 10 chart.ChartAreas(0).AxisY.Interval = 1 chart.ChartAreas(0).AxisY.Minimum = CalcMinYVal(minYVal) I get the CalcMinYVal multiplied...

Date interval sum and subtraction in Java

java,date,sum,intervals,subtraction
I'm looking for a library or helper class in Java that would allow me to perform date interval sum and subtractions. For example, lets's say I have the following date intervals: A = ["2015-01-01 00:00", "2015-01-20 00:00"] B = ["2015-01-05 00:00", "2015-01-10 00:00"] C = ["2015-01-11 00:00", "2015-01-14 00:00"] D...

How to calculate number of days since start of year with DateTime while accounting for leap years?

php,datetime,intervals
I'm trying to use a DateTime object to calculate the current date from the number of days since Jan 1st. Leap years are very important here. Apparently, this does not account for leap years, however. Here's my code: $date = DateTime::createFromFormat('z Y', '59 2016'); echo $date->format('n/j/Y')."\n"; die(); ...

Swift Repeat Interval

uisegmentedcontrol,intervals
I have an app I'm working on with a UISegmentedControl to allow the user to select a repeat interval for the notification they are creating. They also pick the date and time to start, by selecting it on the UIDatePicker. //Variables for Repeat (SegmentedControl) var hourly = true var daily...

Fastest way to find intervals which contain a given point in time

c#,algorithm,datetime,intervals
I need to create time based “Schedule structure”, with following methods: Void addTask(DateTime startTime, int durationInMinutes, TaskObject myObj) { // add TaskObject to calendar structure } List<TaskObject> getRunningTasks (DateTime startTime, DateTime endTime) { //this procedure have to efficiently return list of running tasks in specified time frame } List<TaskObject> getRunningTasks...

How to count the number of values that are between intervals in excel

excel,intervals
Problem Let v = {v1, v2, v3,.., vn} be a set of unsorted real numbers. I want to count to number of values vi that fall in the intervals [0,10], [20,28] etc. Example Let v = {2.6, 3.1, 7, 10, 22, 21, 27} The number of values that fall in...

Coding a Calculator on Python

python,python-3.x,calculator,intervals
So I'm trying to program a calculator that operates with 5 digits, and then check its interval. Here is the code: def CR5(x): x=float('%s' % float('%.5g' % x)) x="{:.4e}".format(x) return x This seems to be working fine, except that the answer is in string form, but that isn't a problem...

overlapping of 3 intervals: what is the fastest way

javascript,python,logic,intervals,overlapping
Give 3 intervals (a,b) , (c,d) , (e,f), what is the fastest way to detect (i.e. have a yes/no answer) if exists a value t that is at the same time a<=t<b AND c<=t<d AND e<=t<f ? Is it also possible to compute the range of t that satisfies this...

TIMESTAMP WITHOUT TIME ZONE, INTERVAL and DST extravaganza

ruby-on-rails,postgresql,intervals,dst,postgresql-9.4
I'm working on a Rails application which stores all dates to PostgreSQL as "TIMESTAMP WITHOUT TIME ZONE". (Rails handles the time zone on the application layer which for this application is "Europe/Berlin".) Unfortunately, Daylight Savings Time (DST) becomes an issue. The simplified "projects" table has the following columns: started_at TIMESTAMP...

How to stop $interval on leaving ui-state?

angularjs,intervals,angularjs-ui-router
Angular, UI-router. Using $interval in a controller of a state like so: $scope.Timer = null; $scope.startTimer = function () { $scope.Timer = $interval($scope.Foo, 30000); }; $scope.stopTimer = function () { if (angular.isDefined($scope.Timer)) { $interval.cancel($scope.Timer); } }; The problem? The timer persists upon leaving the state. My understanding was that the...

Matplotlib: Find a region on a graph by mouse click

python,matplotlib,coordinates,mouse,intervals
Suppose I have a program that plots sine and cosine functions. I want to be able to select a subinterval or region that is created by the graphs, such as π/4 < x < 5π/4 or -3π/4 < x < π/4. So if I have this: import numpy as np...