404

[ Avaa Bypassed ]




Upload:

Command:

botdev@3.22.216.158: ~ $
/**
 * Module exports.
 */

module.exports = weekdayRange;

/**
 * Only the first parameter is mandatory. Either the second, the third, or both
 * may be left out.
 *
 * If only one parameter is present, the function yeilds a true value on the
 * weekday that the parameter represents. If the string "GMT" is specified as
 * a second parameter, times are taken to be in GMT, otherwise in local timezone.
 *
 * If both wd1 and wd1 are defined, the condition is true if the current weekday
 * is in between those two weekdays. Bounds are inclusive. If the "GMT" parameter
 * is specified, times are taken to be in GMT, otherwise the local timezone is
 * used.
 *
 * Valid "weekday strings" are:
 *
 *     SUN MON TUE WED THU FRI SAT
 *
 * Examples:
 *
 * ``` js
 * weekdayRange("MON", "FRI")
 * true Monday trhough Friday (local timezone).
 *
 * weekdayRange("MON", "FRI", "GMT")
 * same as above, but GMT timezone.
 *
 * weekdayRange("SAT")
 * true on Saturdays local time.
 *
 * weekdayRange("SAT", "GMT")
 * true on Saturdays GMT time.
 *
 * weekdayRange("FRI", "MON")
 * true Friday through Monday (note, order does matter!).
 * ```
 *
 * 
 * @param {String} wd1 one of the weekday strings.
 * @param {String} wd2 one of the weekday strings.
 * @param {String} gmt is either the string: GMT or is left out.
 * @return {Boolean}
 */

const dayOrder = { "SUN": 0, "MON": 1, "TUE": 2, "WED": 3, "THU": 4, "FRI": 5, "SAT": 6 };

function weekdayRange (wd1, wd2, gmt) {

  var useGMTzone = (wd2 == "GMT" || gmt == "GMT"),
      todaysDay  = getTodaysDay(useGMTzone),
      wd1Index   = dayOrder[wd1] || -1,
      wd2Index   = dayOrder[wd2] || -1,
      result     = false;

  if (wd2Index < 0) {
    result = (todaysDay == wd1Index);
  } else {
    if (wd1Index <= wd2Index) {
      result = valueInRange(wd1Index, todaysDay, wd2Index);
    } else {
      result = valueInRange(wd1Index, todaysDay, 6) || valueInRange(0, todaysDay, wd2Index);
    }
  }
  return result;
}

function getTodaysDay (gmt) {
  return (gmt ? (new Date()).getUTCDay() : (new Date()).getDay());
}

// start <= value <= finish
function valueInRange (start, value, finish) {
  return (start <= value) && (value <= finish);
}

Filemanager

Name Type Size Permission Actions
test Folder 0755
.npmignore File 61 B 0644
.travis.yml File 318 B 0644
CHANGELOG.md File 6.03 KB 0644
README.md File 3.04 KB 0644
dateRange.js File 2.28 KB 0644
dnsDomainIs.js File 699 B 0644
dnsDomainLevels.js File 561 B 0644
dnsResolve.js File 638 B 0644
index.js File 3.49 KB 0644
isInNet.js File 1.27 KB 0644
isPlainHostName.js File 439 B 0644
isResolvable.js File 425 B 0644
localHostOrDomainIs.js File 1.1 KB 0644
myIpAddress.js File 1.01 KB 0644
package.json File 2.48 KB 0644
shExpMatch.js File 997 B 0644
timeRange.js File 3.19 KB 0644
weekdayRange.js File 2.14 KB 0644