Run a function periodically in Scala

You could use standard stuff from java.util.concurrent: import java.util.concurrent._ val ex = new ScheduledThreadPoolExecutor(1) val task = new Runnable { def run() = println(“Beep!”) } val f = ex.scheduleAtFixedRate(task, 1, 1, TimeUnit.SECONDS) f.cancel(false) Or java.util.Timer: val t = new java.util.Timer() val task = new java.util.TimerTask { def run() = println(“Beep!”) } t.schedule(task, 1000L, 1000L) task.cancel()

Generate a list of datetimes between an interval

Use datetime.timedelta: from datetime import date, datetime, timedelta def perdelta(start, end, delta): curr = start while curr < end: yield curr curr += delta >>> for result in perdelta(date(2011, 10, 10), date(2011, 12, 12), timedelta(days=4)): … print result … 2011-10-10 2011-10-14 2011-10-18 2011-10-22 2011-10-26 2011-10-30 2011-11-03 2011-11-07 2011-11-11 2011-11-15 2011-11-19 2011-11-23 2011-11-27 2011-12-01 2011-12-05 2011-12-09 … Read more

Period to string [duplicate]

You need to normalize the period because if you construct it with the total number of seconds, then that’s the only value it has. Normalizing it will break it down into the total number of days, minutes, seconds, etc. Edit by ripper234 – Adding a TL;DR version: PeriodFormat.getDefault().print(period) For example: public static void main(String[] args) … Read more

Using a variable period in an interval in Postgres

Use this line: startDate TIMESTAMP := endDate – ($3 || ‘ MONTH’)::INTERVAL; and note the space before MONTH. Basically: You construct a string with like 4 MONTH and cast it with ::type into a proper interval. Edit: I’ have found another solution: You can calculate with interval like this: startDate TIMESTAMP := endDate – $3 … Read more

What does ‘PT’ prefix stand for in Duration?

As can be found on the page Jesper linked to (ISO-8601 – Data elements and interchange formats – Information interchange – Representation of dates and times) P is the duration designator (for period) placed at the start of the duration representation. Y is the year designator that follows the value for the number of years. … Read more