[Forms] Get date-time as UNIX timestamp

Get date-time as a UNIX timestamp (in milliseconds
since start of 1970) add the model level for date-time
controls. WTD-530.
This commit is contained in:
Victor Woeltjen 2014-11-28 13:35:24 -08:00
parent a464fee6df
commit aaa0ff768d
3 changed files with 29 additions and 8 deletions

6
platform/forms/lib/moment.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -23,6 +23,10 @@
<input type='text'
name='hour'
maxlength='2'
min='0'
max='23'
integer
ng-pattern='/\d+/'
ng-model="datetime.hour"
ng-required='true'/>
</span>
@ -30,6 +34,10 @@
<input type='text'
name='min'
maxlength='2'
min='0'
max='59'
integer
ng-pattern='/\d+/'
ng-model="datetime.min"
ng-required='true'/>
</span>
@ -37,6 +45,10 @@
<input type='text'
name='sec'
maxlength='2'
min='0'
max='59'
integer
ng-pattern='/\d+/'
ng-model="datetime.sec"
ng-required='true'/>
</span>

View File

@ -1,23 +1,26 @@
/*global define*/
define(
[],
["../../lib/moment.min"],
function () {
var DATE_FORMAT = "YYYY-DDD";
function DateTimeController($scope) {
function update() {
var date = $scope.datetime.date,
hour = $scope.datetime.hour,
min = $scope.datetime.min,
sec = $scope.datetime.sec;
sec = $scope.datetime.sec,
fullDateTime = moment.utc(date, DATE_FORMAT)
.hour(hour || 0)
.minute(min || 0)
.second(sec || 0);
$scope.ngModel[$scope.field] = [
date,
hour,
min,
sec
].join(".");
if (fullDateTime.isValid()) {
$scope.ngModel[$scope.field] = fullDateTime.valueOf();
}
}
$scope.$watch("datetime.date", update);