'use strict';

var moment = require('moment');

/**
 * Adjust for amesh
 */
var getAdjustedMoment = exports.getAdjustedMoment = function() {
  var m = moment();
  var tail = m.format('mm').substring(1, 2);
  var num = ((1 <= +tail) && (+tail <= 5)) ? 0 : 5;
  m.add((num - tail), 'minutes');
  return m;
};

/**
 * Returns specified format string
 */
exports.format = function(pattern) {
  var m = getAdjustedMoment();
  return m.format(pattern);
};

@@ -164,15 +164,19 @@
 var 
-tail
+minutes
  = 
++
 m.fo
@@ -220,45 +220,171 @@
  = (
-(1 %3C= +tail) && (+tail %3C= 5)) ? 0 : 5
+function() %7B%0A    if (minutes === 0) %7B%0A      return -5;%0A    %7D else if ((1 %3C= minutes) && (minutes %3C= 5)) %7B%0A      return 0;%0A    %7D else %7B%0A      return 5;%0A    %7D%0A  %7D)()
 ;%0A  
@@ -400,12 +400,15 @@
 m - 
-tail
+minutes
 ), '

Fix time calculation