Browse Source

Pad zeros in timestamp

Months, dates, hours and minutes are now padded with zeros
Thomas Dy 10 years ago
parent
commit
82e1609fd4
2 changed files with 22 additions and 2 deletions
  1. 2 2
      lib/ui/Settings.jsx
  2. 20 0
      lib/util.js

+ 2 - 2
lib/ui/Settings.jsx

@@ -1,5 +1,6 @@
 var DomainStore = require('../stores').Domains;
 var React = require('react');
+var dateToString = require('../util').dateToString;
 
 var DevModeToggle = React.createClass({
   getInitialState: function() {
@@ -18,11 +19,10 @@ var DevModeToggle = React.createClass({
     }
     else if(this.props.devMode > 0) {
       var date = new Date(this.props.devMode*1000);
-      var dateString = date.getFullYear()+'/'+(1+date.getMonth())+'/'+date.getDate()+' '+date.getHours()+':'+date.getMinutes();
       return (
         <div>
           <button className='btn btn-success' onClick={this.toggleDevMode}>On</button>
-          <span> Active until {dateString}</span>
+          <span> Active until {dateToString(date)}</span>
         </div>
       );
     }

+ 20 - 0
lib/util.js

@@ -0,0 +1,20 @@
+function pad(num) {
+  if(num < 10) {
+    return '0'+num;
+  }
+  else {
+    return ''+num;
+  }
+}
+
+function dateToString(date) {
+    var dateString =
+      date.getFullYear()+'/'+pad(1+date.getMonth())+'/'+ pad(date.getDate())+
+      ' '+
+      pad(date.getHours())+':'+pad(date.getMinutes());
+    return dateString;
+}
+
+module.exports = {
+  dateToString: dateToString
+}