How to trigger javascript functions in the resourcesFolder on a special day

Moment.js is a great way to work with dates. Here's a quick example:

Run this in the <head> of your document:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script>

(The latest can be found here: http://cdnjs.com/libraries/moment.js/ )

Then, run this as an 'on scene load' for the scene where you running this calculation:

var month = moment().format("M");
var day = moment().date();
var year = moment().format("YYYY");

if (day == 04 && month == 7 && year == 2015 )
 {
 hypeDocument.functions().e01(hypeDocument, element, event);
   }
 if (day == 05 && month == 6 && year == 2015)
 {
 hypeDocument.functions().e02(hypeDocument, element, event);
 }
 
 else
 {
hypeDocument.functions().setup(hypeDocument, element, event);
 }

dateexample.zip (24.4 KB)

More info about this library: http://momentjs.com/docs/#/parsing/

If you wanted to determine if a time is between certain hours, you would detect the time, set a range, and run a conditional based on that range:

var format = 'hh:mm:ss'
var time = moment();
  beforeTime = moment('08:34:00', format);
  afterTime = moment('10:34:00', format);

if (time.isBetween(beforeTime, afterTime)) {

  console.log('is between 8:34 am and 10:34 am')

} else {

  console.log('is not between 8:34am and 10:34 am')

}
5 Likes