angularjs - Moment js counter -
hello every 1 i'm working on task uses moment js want make counter count min,sec , hours toggl.com counter have input field called start , 1 called end want subtract finish start , replace counter value , counter continue current value ex counter 0:00:10
, start is: 01:15 pm
, end : 01:30 pm
want subtract start end result value 00:15
value replaces current value of counter 0:00:10
0:15:00
counter start value , add seconds normal counter 0:15:01
, on please check toggl.com understand mean 2/ want if changed value of start value number 10
, if time pm consider 10 pm
not 10 am
code here can't that
validate(val:string) { let temp =this.starttime; let parsedtime = moment(val, "hh:mm a"); if(parsedtime.isvalid()) { this.starttime = parsedtime.format('hh:mm a') } else { this.starttime = "temp"; console.log("no"); } }
where val
enterd value in start input field want if entered unexpected format replaces previous valid time not temp
string tried this.starttime = this.starttime
doesn't work want validation looks toggl.com please visit
and counter code own work don't expect wanted 1 behaviour
startpause() {// when click on play button this.bs = moment(); this.starttime = this.bs.format('hh:mm a'); this.play = false; this.pause = true; let sec= 0; let min = 0; let hour = 0; this.countup = setinterval(() => { if(sec === 59) { min++; sec = 0; }else if(min > 59) { hour++; min = 0; }else { sec++; } this.timer = `${this.pad(hour)}:${this.pad(min)}:${this.pad(sec)}`; }, 1000); }
app.directive("timerup", function(util,$interval,$timeout){ return { scope: { start: '=' }, require: "?ngmodel", //template: "<input type='text' readonly class='form-control' ng-model='value' > ", link: function(scope, element, attrs, ngmodel){ if (!ngmodel) return; ngmodel.$render = function(){ scope.value = ngmodel.$modelvalue; }; var timeout = 0; $interval(function () { if((scope.start)){ //factory('util', [function () { return element.text(util.dhms(math.floor((new date().gettime() - scope.start.gettime())/ 1000))); } }, 1000); function ontimeout() { //timeout = timeout +1; timeout++; } } }; }); app.factory('util', [function () { return { dhms: function (t) { var days, hours, minutes, seconds; days = math.floor(t / 86400); t -= days * 86400; hours = math.floor(t / 3600) % 24; t -= hours * 3600; minutes = math.floor(t / 60) % 60; t -= minutes * 60; seconds = t % 60; return [ (days)? days + 'd': '', (hours)? hours + 'h':'', minutes + 'm', seconds + 's' ].join(' '); } }; }]); <span timerup ng-model="model" start="start"</span>
start = initial date
wiki
Comments
Post a Comment