Skip to content
This repository has been archived by the owner on Oct 1, 2022. It is now read-only.

Commit

Permalink
changed: properly aliased format-date-time without duplicating code, #65
Browse files Browse the repository at this point in the history
  • Loading branch information
MartijnR committed May 26, 2017
1 parent 03fe386 commit 602b001
Showing 1 changed file with 4 additions and 65 deletions.
69 changes: 4 additions & 65 deletions src/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -4842,71 +4842,6 @@ var XPathJS = (function(){

},

/**
* Alias of format-date
*
* @see http://opendatakit.org/help/form-design/binding/
* @param {Object} a
* @param {Object} b
* @return {StringType}
*/
'format-date-time' : {

fn: function(dateO, format)
{
var i,j,
dateO = new DateType(dateO), //not sure why this did not happen automatically
date = dateO.toDate(),
result = format.toString(),
intPad = function(num, l)
{
var str = num.toString(),
zeros = l - str.length;
for (j=0 ; j < zeros ; j++)
{
str = '0'+str;
}
return str;
};

if (!dateO.toBoolean())
{
return new StringType(date.toString());
}

props = {
'Y' : date.getFullYear(),
'y' : date.getFullYear().toString().substring(2,4),
'm' : intPad((date.getMonth()+1), 2),
'n' : date.getMonth()+1,
'b' : ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][date.getMonth()],
'd' : intPad(date.getDate(), 2),
'e' : date.getDate(),
'H' : intPad(date.getHours(), 2),
'h' : date.getHours(),
'M' : intPad(date.getMinutes(), 2),
'S' : intPad(date.getSeconds(), 2),
'3' : intPad(date.getMilliseconds(), 3),
'a' : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][date.getDay()]
}

for (prop in props)
{
result = result.replace('%'+prop, props[prop]);
}

return new StringType(result);
},

args: [
{t: 'date'},
{t: 'string'}
],

ret: 'string'

},

/**
* The pow function returns exponentiated result
* arguments provided.
Expand Down Expand Up @@ -5447,6 +5382,10 @@ var XPathJS = (function(){
}*/
}
}
/**
* Alias functions
*/
functions[""]['format-date-time'] = functions[""]['format-date'];

/**
* Evaluate parsed expression tree.
Expand Down

0 comments on commit 602b001

Please sign in to comment.