/*
today 代表目标日期，如果没有这个参数默认取“今天” week
代表要取的下一个星期几，如果没有这个参数默认取下一个星期天
172680
function (week, today) {
		var now = new Date();
		if (today) {
			now.setDate(today);
		}
		week = 7 - (week || now.getDay());

		return new Date(now.getTime() + ONE_DAY_MILLISECONDS * week);
	}
1077859
void formatWeekday(StringBuilder b, ZonedDateTime d, int width, FieldVariants weekdays) {
    int weekday = d.getDayOfWeek().getValue() % 7;
    switch (width) {
      case 6:
        b.append(weekdays.short_[weekday]);
        break;

      case 5:
        b.append(weekdays.narrow[weekday]);
        break;

      case 4:
        b.append(weekdays.wide[weekday]);
        break;

      case 3:
      case 2:
      case 1:
        b.append(weekdays.abbreviated[weekday]);
        break;
    }
  }
1279776
def schedule2calendar(schedule, name='课表', using_todo=True):
    
    # https://zh.wikipedia.org/wiki/ICalendar
    # http://icalendar.readthedocs.io/en/latest
    # https://tools.ietf.org/html/rfc5545
    cal = icalendar.Calendar()
    cal.add('X-WR-TIMEZONE', 'Asia/Shanghai')
    cal.add('X-WR-CALNAME', name)
    cls = icalendar.Todo if using_todo else icalendar.Event
    for week, start, end, data in schedule:
        # "事件"组件更具通用性, Google 日历不支持"待办"组件
        item = cls(
            SUMMARY='第{:02d}周-{}'.format(week, data),
            DTSTART=icalendar.vDatetime(start),
            DTEND=icalendar.vDatetime(end),
            DESCRIPTION='起始于 {}, 结束于 {}'.format(start.strftime('%H:%M'), end.strftime('%H:%M'))
        )
        now = datetime.now()
        # 这个状态"事件"组件是没有的, 对于待办列表类应用有作用
        # https://tools.ietf.org/html/rfc5545#section-3.2.12
        if using_todo:
            if start < now < end:
                item.add('STATUS', 'IN-PROCESS')
            elif now > end:
                item.add('STATUS', 'COMPLETED')
        cal.add_component(item)
    return cal
1141867
public static WeekDay getDay(final int calDay) {
        WeekDay day = null;
        switch (calDay) {
            case Calendar.SUNDAY:
                day = SU;
                break;
            case Calendar.MONDAY:
                day = MO;
                break;
            case Calendar.TUESDAY:
                day = TU;
                break;
            case Calendar.WEDNESDAY:
                day = WE;
                break;
            case Calendar.THURSDAY:
                day = TH;
                break;
            case Calendar.FRIDAY:
                day = FR;
                break;
            case Calendar.SATURDAY:
                day = SA;
                break;
            default:
                break;
        }
        return day;
    }
47592
public Weekday getDayOfWeek() {

        long utcDays = this.gregorian.getDaysSinceEpochUTC();
        return Weekday.valueOf(MathUtils.floorModulo(utcDays + 5, 7) + 1);

    }
892057
public Weekday getDayOfWeek() {

        long utcDays = getCalendarSystem(this.variant).transform(this);
        return Weekday.valueOf(MathUtils.floorModulo(utcDays + 5, 7) + 1);

    }
1260354
public static DayOfWeek toDayOfWeek(final Calendar self) {
        return DayOfWeek.of(self.get(Calendar.DAY_OF_WEEK)).minus(1);
    }
1319732
public static DayOfWeek dayOfWeek(DateValue date) {
		int dayIndex = fixedFromGregorian(date.year(), date.month(), date.day()) % 7;
		if (dayIndex < 0) {
			dayIndex += 7;
		}
		return DAYS_OF_WEEK[dayIndex];
	}
1003549
public DayOfTheWeek next() {
        if (this == PH) {
            return null;
        }
        final int nextId = id + 1;
        if (nextId == PH.id) {
            return MON;
        }
        for (final DayOfTheWeek dow : ALL) {
            if (dow.id == nextId) {
                return dow;
            }
        }
        throw new IllegalStateException("Wasn't able to find next day for: " + this);
    }
754422
public com.google.type.DayOfWeek getDayOfWeek() {
    @SuppressWarnings("deprecation")
    com.google.type.DayOfWeek result = com.google.type.DayOfWeek.valueOf(dayOfWeek_);
    return result == null ? com.google.type.DayOfWeek.UNRECOGNIZED : result;
  }
975553
public String getWeekdayRelativeTo(String date, int weekday, int number, boolean count_itself) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		Calendar c = Calendar.getInstance();
				
		int day;
		int add;
		
		if(number == 0) {
			try{
				c.setTime(formatter.parse(date));
				date = formatter.format(c.getTime());
			} catch (ParseException e) {
				e.printStackTrace();
			}
			return date;			
		}
		else{
			
			if(number<0) {
				number+=1;
			}
						
			try{
				c.setTime(formatter.parse(date));
				day = c.get(Calendar.DAY_OF_WEEK);
				if((count_itself && number>0) || (!count_itself && number <= 0)) {
					if(day<=weekday) {
						add = weekday - day;
					}
					else{
						add = weekday - day + 7;
					}	
				}
				else{
					if(day<weekday) {
						add = weekday - day;
					}
					else{
						add = weekday - day + 7;
					}	
				}
				add += (( number - 1) * 7);
				c.add(Calendar.DAY_OF_MONTH, add);
				date = formatter.format(c.getTime());
			} catch (ParseException e) {
				e.printStackTrace();
			}
			return date;
		}
	}
701140
public static int calendarDay2Day(int day) {
        switch (day) {
            case Calendar.SUNDAY:
                return SU;
            case Calendar.MONDAY:
                return MO;
            case Calendar.TUESDAY:
                return TU;
            case Calendar.WEDNESDAY:
                return WE;
            case Calendar.THURSDAY:
                return TH;
            case Calendar.FRIDAY:
                return FR;
            case Calendar.SATURDAY:
                return SA;
            default:
                throw new RuntimeException("bad day of week: " + day);
        }
    }
220877
def get_day_name(self) -> str:
        
        weekday = self.value.isoweekday() - 1
        return calendar.day_name[weekday]
1225243
@Nullable
    public static MultiDayOfTheWeek valueOf(@Nullable final String str) {
        if (str == null) {
            return null;
        }
        return new MultiDayOfTheWeek(str);
    }
1169114
public static int getDayOfWeek(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.DAY_OF_WEEK);
    }
1239920
private String getWeekDayLabel(Calendar day) {
        Locale locale = mController.getLocale();

        // Localised short version of the string is not available on API < 18
        if (Build.VERSION.SDK_INT < 18) {
            String dayName = new SimpleDateFormat("E", locale).format(day.getTime());
            String dayLabel = dayName.toUpperCase(locale).substring(0, 1);

            // Chinese labels should be fetched right to left
            if (locale.equals(Locale.CHINA) || locale.equals(Locale.CHINESE) || locale.equals(Locale.SIMPLIFIED_CHINESE) || locale.equals(Locale.TRADITIONAL_CHINESE)) {
                int len = dayName.length();
                dayLabel = dayName.substring(len - 1, len);
            }

            // Most hebrew labels should select the second to last character
            if (locale.getLanguage().equals("he") || locale.getLanguage().equals("iw")) {
                if (mDayLabelCalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) {
                    int len = dayName.length();
                    dayLabel = dayName.substring(len - 2, len - 1);
                } else {
                    // I know this is duplication, but it makes the code easier to grok by
                    // having all hebrew code in the same block
                    dayLabel = dayName.toUpperCase(locale).substring(0, 1);
                }
            }

            // Catalan labels should be two digits in lowercase
            if (locale.getLanguage().equals("ca"))
                dayLabel = dayName.toLowerCase().substring(0, 2);

            // Correct single character label in Spanish is X
            if (locale.getLanguage().equals("es") && day.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY)
                dayLabel = "X";

            return dayLabel;
        }
        // Getting the short label is a one liner on API >= 18
        if (weekDayLabelFormatter == null) {
            weekDayLabelFormatter = new SimpleDateFormat("EEEEE", locale);
        }
        return weekDayLabelFormatter.format(day.getTime());
    }
1302807
def this_week_day(base_date, weekday):
    
    day_of_week = base_date.weekday()
    # If today is Tuesday and the query is `this monday`
    # We should output the next_week monday
    if day_of_week > weekday:
        return next_week_day(base_date, weekday)
    start_of_this_week = base_date - timedelta(days=day_of_week + 1)
    day = start_of_this_week + timedelta(days=1)
    while day.weekday() != weekday:
        day = day + timedelta(days=1)
    return day