/*
Parse a number into day of week, or a month name;
used in dateList below.
484269
function(value, type) {
    if (type === 'dow') {
      return moment().day(value - 1).format('ddd');
    } else if (type === 'mon') {
      return moment().month(value - 1).format('MMM');
    }
  }
60155
def _parse_day(optval):
        '''  '''
        isreq = not optval.startswith('+')
        if not isreq:
            optval = optval[1:]

        try:
            retnval = []
            unit = None
            for val in optval.split(','):
                if not val:
                    raise ValueError
                if val[-1].isdigit():
                    newunit = 'dayofmonth' if isreq else 'day'
                    if unit is None:
                        unit = newunit
                    elif newunit != unit:
                        raise ValueError
                    retnval.append(int(val))
                else:
                    newunit = 'dayofweek'
                    if unit is None:
                        unit = newunit
                    elif newunit != unit:
                        raise ValueError

                    weekday = Cron._parse_weekday(val)
                    if weekday is None:
                        raise ValueError
                    retnval.append(weekday)
            if len(retnval) == 0:
                raise ValueError
        except ValueError:
            return None, None
        if len(retnval) == 1:
            retnval = retnval[0]
        return unit, retnval
763759
function (d) {
		"use strict";

		if (typeof d === "number") {
			d = new Date(d);
		}

		var monthFirstWeekNumber = this.getWeekNumber(new Date(d.getFullYear(), d.getMonth()));
		return this.getWeekNumber(d) - monthFirstWeekNumber - 1;
	}
425431
def parse_date(self, value):
        """"""
        res = dateparser.parse(
            value, date_formats=self.options['date_formats'], languages=self.options['languages']
        )
        logger.debug("result of date parsing=%s", res)
        return res
795770
private Map<String, Integer> parseFirstDays(JsonObject root) {
    JsonObject node = resolve(root, "supplemental", "weekData", "firstDay");
    Map<String, Integer> m = new HashMap<>();
    for (String key : objectKeys(node)) {
      String value = string(node, key);
      m.put(key, NUMERIC_DAYS.get(value));
    }
    return m;
  }
1285878
def dayname(year, month, day):
    '''
    
    '''
    legal_date(year, month, day)

    yearday = (month - 1) * 28 + day

    if isleap(year + YEAR_EPOCH - 1):
        dname = data.day_names_leap[yearday - 1]
    else:
        dname = data.day_names[yearday - 1]

    return MONTHS[month - 1], dname
401515
function formatDate(d, fmt, monthNames, dayNames) {

		if (typeof d.strftime == "function") {
			return d.strftime(fmt);
		}

		var leftPad = function(n, pad) {
			n = "" + n;
			pad = "" + (pad == null ? "0" : pad);
			return n.length == 1 ? pad + n : n;
		};

		var r = [];
		var escape = false;
		var hours = d.getHours();
		var isAM = hours < 12;

		if (monthNames == null) {
			monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
		}

		if (dayNames == null) {
			dayNames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
		}

		var hours12;

		if (hours > 12) {
			hours12 = hours - 12;
		} else if (hours == 0) {
			hours12 = 12;
		} else {
			hours12 = hours;
		}

		for (var i = 0; i < fmt.length; ++i) {

			var c = fmt.charAt(i);

			if (escape) {
				switch (c) {
					case 'a': c = "" + dayNames[d.getDay()]; break;
					case 'b': c = "" + monthNames[d.getMonth()]; break;
					case 'd': c = leftPad(d.getDate()); break;
					case 'e': c = leftPad(d.getDate(), " "); break;
					case 'h':	// For back-compat with 0.7; remove in 1.0
					case 'H': c = leftPad(hours); break;
					case 'I': c = leftPad(hours12); break;
					case 'l': c = leftPad(hours12, " "); break;
					case 'm': c = leftPad(d.getMonth() + 1); break;
					case 'M': c = leftPad(d.getMinutes()); break;
					// quarters not in Open Group's strftime specification
					case 'q':
						c = "" + (Math.floor(d.getMonth() / 3) + 1); break;
					case 'S': c = leftPad(d.getSeconds()); break;
					case 'y': c = leftPad(d.getFullYear() % 100); break;
					case 'Y': c = "" + d.getFullYear(); break;
					case 'p': c = (isAM) ? ("" + "am") : ("" + "pm"); break;
					case 'P': c = (isAM) ? ("" + "AM") : ("" + "PM"); break;
					case 'w': c = "" + d.getDay(); break;
				}
				r.push(c);
				escape = false;
			} else {
				if (c == "%") {
					escape = true;
				} else {
					r.push(c);
				}
			}
		}

		return r.join("");
	}
717413
public NumberExpression<Integer> dayOfWeek() {
        if (dayOfWeek == null) {
            dayOfWeek = Expressions.numberOperation(Integer.class, Ops.DateTimeOps.DAY_OF_WEEK, mixin);
        }
        return dayOfWeek;
    }
806500
function monthCalendar(date) {
    var start = date.clone().startOf("month").startOf("week").startOf("day");
    var end = date.clone().endOf("month").endOf("week").startOf("day");
    var result = [];
    var current = start.weekday(0).subtract(1, "d");
    while (true) {
        current = current.clone().add(1, "d");
        result.push(current);
        if (areDatesEqual(current, end)) {
            break;
        }
    }
    return result;
}
624890
private WeekDay readWeekDay(JSONValue val) throws IllegalArgumentException {

        String str = readOptionalString(val);
        if (null != str) {
            return WeekDay.valueOf(str);
        }
        throw new IllegalArgumentException();
    }
1156293
function getDayOfMonth (date, month) {
  date = toStringDate(date)
  if (baseExports.isDate(date)) {
    return Math.floor((getDateTime(getWhatMonth(date, month, STRING_LAST)) - getDateTime(getWhatMonth(date, month, STRING_FIRST))) / DAY_TIME) + 1
  }
  return date
}
1231150
public static MonthDay parse(String str, DateTimeFormatter formatter) {
        LocalDate date = formatter.parseLocalDate(str);
        return new MonthDay(date.getMonthOfYear(), date.getDayOfMonth());
    }
310076
function d3_time_parseWeekday(date, string, i) {
  d3_time_weekdayRe.lastIndex = 0;
  var n = d3_time_weekdayRe.exec(string.substring(i, i + 10));
  return n ? i += n[0].length : -1;
}
1183555
function weekNumber(d, firstWeekday) {
		firstWeekday = firstWeekday || 'sunday';
		// This works by shifting the weekday back by one day if we
		// are treating Monday as the first day of the week.
		var wday = d.getDay();
		if (firstWeekday == 'monday') {
			if (wday == 0) // Sunday
				wday = 6;
			else
				wday--;
		}
		var firstDayOfYear = new Date(d.getFullYear(), 0, 1)
			, yday = (d - firstDayOfYear) / 86400000
			, weekNum = (yday + 7 - wday) / 7
			;
		//    return Math.floor(weekNum);
		return weekNum | 0;
	}
646276
public void parse (final int nYear, final HolidayMap aHolidayMap, final Holidays aConfig)
  {
    for (final FixedWeekdayRelativeToFixed aFixedWeekdayRelativeToFixed : aConfig.getFixedWeekdayRelativeToFixed ())
    {
      if (!isValid (aFixedWeekdayRelativeToFixed, nYear))
        continue;

      // parsing fixed day
      final DayOfWeek nExpectedWeekday = XMLHolidayHelper.getWeekday (aFixedWeekdayRelativeToFixed.getWeekday ());
      LocalDate aDay = XMLHolidayHelper.create (nYear, aFixedWeekdayRelativeToFixed.getDay ());
      do
      {
        // move fixed to first occurrence of weekday
        aDay = aFixedWeekdayRelativeToFixed.getWhen () == When.AFTER ? aDay.plusDays (1) : aDay.minusDays (1);
      } while (aDay.getDayOfWeek () != nExpectedWeekday);
      int nDays = 0;
      switch (aFixedWeekdayRelativeToFixed.getWhich ())
      {
        case FIRST:
          break;
        case SECOND:
          nDays = 7;
          break;
        case THIRD:
          nDays = 14;
          break;
        case FOURTH:
          nDays = 21;
          break;
        case LAST:
          // seems to be unsupported
          break;
      }
      // move day further if it is second, third or fourth weekday
      aDay = aFixedWeekdayRelativeToFixed.getWhen () == When.AFTER ? aDay.plusDays (nDays) : aDay.minusDays (nDays);
      final IHolidayType aType = XMLHolidayHelper.getType (aFixedWeekdayRelativeToFixed.getLocalizedType ());
      final String sPropertyKey = aFixedWeekdayRelativeToFixed.getDescriptionPropertiesKey ();
      aHolidayMap.add (aDay, new ResourceBundleHoliday (aType, sPropertyKey));
    }
  }
583279
function getWeekNumber(day) {
  var date = clone(day);
  date.setHours(0, 0, 0);
  date.setDate(date.getDate() + 4 - (date.getDay() || 7));
  return Math.ceil(((date - new Date(date.getFullYear(), 0, 1)) / 8.64e7 + 1) / 7);
}
231032
@Nonnull
  public static DayOfWeek getAsDayOfWeek (final int nCalendarDayOfWeek)
  {
    ValueEnforcer.isBetweenInclusive (nCalendarDayOfWeek, "DayOfWeek", 1, 7);
    // Convert Calendar DoW to enum DoW
    final int nIndex = (nCalendarDayOfWeek + 6) % 7;
    return DayOfWeek.of (nIndex == 0 ? 7 : nIndex);
  }