Priyanka Maurya
Priyanka Maurya

Reputation: 443

hours and minutes to seconds

I want to convert hours and minutes into seconds which will be send to the API but I am not getting converted seconds. And what value I should send to API.

Html:

<form ng-submit="vm.handleAddBrief(vm.briefAttractionData)">
<div class="form-group">
        <label class="control-label col-md-3">Duration
        </label>
        <div class="col-md-6">
            <div class="input-group input-medium margin-top-10" name="duration">
                <input type="text" class="form-control" ng-model="vm.briefAttractionData.hours">
                <span class="input-group-addon">
                                                                   hrs
                                                                 </span>
                <input type="text" class="form-control" ng-model="vm.briefAttractionData.minutes">
                <span class="input-group-addon">
                                                                  mins
                                                                 </span>
                <!--{{seconds | secondsToDateTime | date:'HH:mm:ss'}}-->

            </div>
        </div>
      </form>

Controller:

function addBriefController($scope, $state, $timeout, $location, addBriefService) {

        var vm = this;

        vm.handleAddBrief = function (data) {
            var duration = function(data) {
               var hrs = Math.floor(data.hours * 3600);
               var min = Math.floor( data.minutes * 60);
               var totalSeconds = Math.floor(hrs + min);
            }


        addBriefService.addBrief(data, function (response) {    
            if (response.status === 200) {
                $state.go('newAttraction.image');
            } else {
                $state.go('newAttraction.image');
            }
        });
}

Upvotes: 1

Views: 191

Answers (1)

Pratik Bhattacharya
Pratik Bhattacharya

Reputation: 3746

Why do you have the 'duration' function inside the handleAddBrief code. On submitting the form from UI, the handleAddBrief function is getting called and the 'duration' function is being initialized but it is not getting called. Either explicitly call the 'duration' function inside the 'handleAddBrief' function or remove it.
I have created a fiddle for the solution, you can take a look: http://jsfiddle.net/azwspw3x/1/
The code looks something like below:

$scope.handleAddBrief = function (data) {
           var hrs = Math.floor(data.hours * 3600);
           var min = Math.floor( data.minutes * 60);
           var totalSeconds = Math.floor(hrs + min);
           $scope.ts = totalSeconds
        }
}

Upvotes: 1

Related Questions