rankind rankind - 1 month ago 10
Javascript Question

Javascript Warp Time with Warp js

I'm working on a project where I need to manipulate time speed forward and backward. This module seems like what I need but I can't get it working:

https://github.com/mattbradley/warpjs/blob/master/README.md

Any help appreciated

<html>
<head>
</head>

<body>
<script src="jquery.min.js"></script>
<script src="warp.js"></script>


<div id="container"></div>
<span id="info"></span><br>
<span id="time"></span>
<span id="time2"></span>

<script>


setInterval(function() {
var now = new Date;
now = Date.warp.clock(true);
//now = Date.warp.speed(2); // DOESNT WORK?

var dateD = [now.getMonth() + 1,now.getDate(),now.getFullYear()];
var dateE = [now.getHours(),now.getMinutes(),now.getSeconds()];
var MDY = dateD.join("/");
var HMS = dateE.join(":");
time.innerHTML = (MDY);
time2.innerHTML = (HMS);

}, 20);


</script>

</body>

</html>

Answer

The wrap is a static method, it doesn't return any value(undefined is returned)

setInterval(function() {
  Date.warp.speed(3);
  var now = new Date;

  var dateD = [now.getMonth() + 1, now.getDate(), now.getFullYear()];
  var dateE = [now.getHours(), now.getMinutes(), now.getSeconds()];
  var MDY = dateD.join("/");
  var HMS = dateE.join(":");
  time.innerHTML = (MDY);
  time2.innerHTML = (HMS);

}, 1000);

Demo: Fiddle

Comments