Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module.exports = function () {
  2.   var dateTime = {
  3.     days: [],
  4.     months: [],
  5.     years: [],
  6.     hours: [],
  7.     minutes: [],
  8.     start: new DateTime('1', '1', '2017', '1', '0'),
  9.     end: new DateTime('2', '1', '2017', '1', '0')
  10.   }
  11.   // setup values for dates and time
  12.   for (var i = 1; i < 32; i++) {
  13.     dateTime.days.push(i.toString())
  14.   }
  15.   for (var i = 1; i < 13; i++) {
  16.     dateTime.months.push(i.toString())
  17.   }
  18.   for (var i = 2010; i < 2026; i++) {
  19.     dateTime.years.push(i.toString())
  20.   }
  21.   for (var i = 0; i < 24; i++) {
  22.     dateTime.hours.push(i.toString())
  23.   }
  24.   for (var i = 0; i < 60; i++) {
  25.     dateTime.minutes.push(i.toString())
  26.   }
  27.  
  28.   return dateTime
  29. }
  30.  
  31. var DateTime = module.exports.DateTime = function (day, month, year, hour, minute) {
  32.   this.day = day ? day : 1
  33.   this.month = month ? month : 1
  34.   this.year = year ? year : 2017
  35.   this.hour = hour ? hour : 12
  36.   this.minute = minute ? minute : 0
  37.   this.months = [
  38.     'NotAMonth',
  39.     'JAN',
  40.     'FEB',
  41.     'MAR',
  42.     'APR',
  43.     'MAY',
  44.     'JUN',
  45.     'JUL',
  46.     'AUG',
  47.     'SEP',
  48.     'OCT',
  49.     'NOV',
  50.     'DEC'
  51.   ]
  52.  
  53.   this.timeFormat = function(z) {
  54.     return ('0' + z).slice(-2)
  55.   }
  56.   this.toString = function() {
  57.     var str =
  58.       this.timeFormat(this.day) +
  59.       '-' +
  60.       this.months[this.month] +
  61.       '-' +
  62.       this.year +
  63.       ' ' +
  64.       this.timeFormat(this.hour) +
  65.       ':' +
  66.       this.timeFormat(this.minute) +
  67.       ':00.00 ' +
  68.       (this.hour < 12 ? 'AM' : 'PM')
  69.     return str
  70.   }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement