Easy countdown

Hi Creator, i found this link to create a countdown but i’m not good at integrating it on spark. Is there a way to create a countdown with patches?
I tried to follow the tutorials on the contdowns of Newcolor but I couldn’t create a working one.

Well, ideally this script would mostly work in spark without having to do too much to it, but it seems like you’ve discovered a bug! The date string parsing in spark is broken, but you can just as easily open devtools in chrome and paste that line into it to get the millisecond value.

const Time = require('Time')
const Patches = require('Patches')
const {log} = require('Diagnostics')

// Set the date we're counting down to
// var countDownDate = new Date("Jan 5, 2021 15:37:25")
// log(countDownDate)

// need to get this in web browser devtools console by pasting `new Date("Jan 5, 2021 15:37:25")` with your target date
var countDownDate = 1609879045000

// Update the count down every 1 second
var x = Time.setInterval(() => {

  // Get today's date and time
  var now = Date.now()

  // Find the distance between now and the count down date
  var distance = countDownDate - now

  // Time calculations for days, hours, minutes and seconds
  var days = Math.floor(distance / (1000 * 60 * 60 * 24))
  var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
  var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60))
  var seconds = Math.floor((distance % (1000 * 60)) / 1000)

  var dateString = days + "d " + hours + "h " + minutes + "m " + seconds + "s"

  // send the string to patches
  Patches.inputs.setString('countdown', dateString)

  // set boolean in patches
  if (distance < 0) {
    Time.clearInterval(x)
    Patches.inputs.setBoolean('countdownComplete', true)
  }
}, 1000)

spark-countdown-timer.arexport (185.8 KB)

Screen Shot 2020-11-05 at 4.26.02 PM

EDIT:

I dug into the Hermes JS runtime and found a list of supported date formats, which should all work in Spark.

1 Like

Thank you very much Josh, You are a wizard :rofl:

1 Like

How do I get this var countDownDate = 1609879045000 from my web browser devtools console ?

Try this: Screen Shot 2020-11-09 at 8.45.41 AM

Thank you @josh_beckwith for the script :heart:
I calculated the date using this site; https://codechi.com/dev-tools/date-to-millisecond-calculators/comment-page-1/
Perhaps someone will need this in the future

2 Likes