本文整理汇总了Java中java.util.Calendar.WEEK_OF_YEAR属性的典型用法代码示例。如果您正苦于以下问题:Java Calendar.WEEK_OF_YEAR属性的具体用法?Java Calendar.WEEK_OF_YEAR怎么用?Java Calendar.WEEK_OF_YEAR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.util.Calendar
的用法示例。
在下文中一共展示了Calendar.WEEK_OF_YEAR属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: translate
private static int translate(final IntervalUnit unit) {
switch (unit) {
case DAY:
return Calendar.DAY_OF_YEAR;
case HOUR:
return Calendar.HOUR_OF_DAY;
case MINUTE:
return Calendar.MINUTE;
case MONTH:
return Calendar.MONTH;
case SECOND:
return Calendar.SECOND;
case MILLISECOND:
return Calendar.MILLISECOND;
case WEEK:
return Calendar.WEEK_OF_YEAR;
case YEAR:
return Calendar.YEAR;
default:
throw new IllegalArgumentException("Unknown IntervalUnit");
}
}
示例2: previous
/**
* Operation is based on java util calendar in order to support daylight
* saving times.
*/
public TimeSlice previous() {
long newStart = start;
long newEnd = end;
Calendar temp = Calendar.getInstance();
temp.setTimeInMillis(start);
int field = 0;
switch (period) {
case HOUR:
field = Calendar.HOUR_OF_DAY;
break;
case DAY:
field = Calendar.DAY_OF_MONTH;
break;
case WEEK:
field = Calendar.WEEK_OF_YEAR;
break;
case MONTH:
field = Calendar.MONTH;
break;
default:
break;
}
temp.add(field, -1);
newStart = temp.getTimeInMillis();
temp.setTimeInMillis(end);
temp.add(field, -1);
newEnd = temp.getTimeInMillis();
return new TimeSlice(newStart, newEnd, period);
}
示例3: translate
private static int translate(IntervalUnit unit) {
switch(unit) {
case DAY : return Calendar.DAY_OF_YEAR;
case HOUR : return Calendar.HOUR_OF_DAY;
case MINUTE : return Calendar.MINUTE;
case MONTH : return Calendar.MONTH;
case SECOND : return Calendar.SECOND;
case MILLISECOND : return Calendar.MILLISECOND;
case WEEK : return Calendar.WEEK_OF_YEAR;
case YEAR : return Calendar.YEAR;
default : throw new IllegalArgumentException("Unknown IntervalUnit");
}
}
示例4: getDateFieldFromRepeatType
private static int getDateFieldFromRepeatType(ReminderRepeatType repeatType) {
switch (repeatType) {
case DAILY: return Calendar.DAY_OF_MONTH;
case WEEKLY: return Calendar.WEEK_OF_YEAR;
case MONTHLY: return Calendar.MONTH;
case YEARLY: return Calendar.YEAR;
default: throw new InvalidParameterException("Invalid RepeatType parameter in TaskUtil.getRepeatingReminderEndCalendar()");
}
}
示例5: checkTime
private boolean checkTime(Date date, int kind) {
Calendar currentCalendar = Calendar.getInstance();
currentCalendar.setTime(Utils.getAnalyticsDate());
Calendar orderCalendar = Calendar.getInstance();
orderCalendar.setTime(date);
switch (kind) {
case Calendar.DATE:
if (orderCalendar.get(Calendar.YEAR) == currentCalendar.get(Calendar.YEAR) &&
orderCalendar.get(Calendar.MONTH) == currentCalendar.get(Calendar.MONTH) &&
orderCalendar.get(Calendar.DATE) == currentCalendar.get(Calendar.DAY_OF_MONTH)) {
return true;
}
break;
case Calendar.WEEK_OF_YEAR:
if (orderCalendar.get(Calendar.YEAR) == currentCalendar.get(Calendar.YEAR) &&
orderCalendar.get(Calendar.WEEK_OF_YEAR) == currentCalendar.get(Calendar.WEEK_OF_YEAR)) {
return true;
}
break;
case Calendar.MONTH:
if (orderCalendar.get(Calendar.YEAR) == currentCalendar.get(Calendar.YEAR) &&
orderCalendar.get(Calendar.MONTH) == currentCalendar.get(Calendar.MONTH)) {
return true;
}
break;
default:
return false;
}
return false;
}
示例6: makeDatesEven
/**
* Makes dates even, in the sense of that years always begin in January,
* months always begin on the 1st and days always at midnight.
*
* @param dates The list of dates.
* @return The new list of dates.
*/
private List<Date> makeDatesEven(List<Date> dates, Calendar calendar) {
// If the dates contain more dates than just the lower and upper bounds, make the dates in between even.
if (dates.size() > 2) {
List<Date> evenDates = new ArrayList<>();
// For each interval, modify the date slightly by a few millis, to make sure they are different days.
// This is because Axis stores each value and won't update the tick labels, if the value is already known.
// This happens if you display days and then add a date many years in the future the tick label will still be displayed as day.
for (int i = 0; i < dates.size(); i++) {
calendar.setTime(dates.get(i));
switch (actualInterval.interval) {
case Calendar.YEAR:
// If its not the first or last date (lower and upper bound), make the year begin with first month and let the months begin with first day.
if (i != 0 && i != dates.size() - 1) {
calendar.set(Calendar.MONTH, 0);
calendar.set(Calendar.DATE, 1);
}
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 6);
break;
case Calendar.MONTH:
// If its not the first or last date (lower and upper bound), make the months begin with first day.
if (i != 0 && i != dates.size() - 1) {
calendar.set(Calendar.DATE, 1);
}
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 5);
break;
case Calendar.WEEK_OF_YEAR:
// Make weeks begin with first day of week?
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 4);
break;
case Calendar.DATE:
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 3);
break;
case Calendar.HOUR:
if (i != 0 && i != dates.size() - 1) {
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
}
calendar.set(Calendar.MILLISECOND, 2);
break;
case Calendar.MINUTE:
if (i != 0 && i != dates.size() - 1) {
calendar.set(Calendar.SECOND, 0);
}
calendar.set(Calendar.MILLISECOND, 1);
break;
case Calendar.SECOND:
calendar.set(Calendar.MILLISECOND, 0);
break;
}
evenDates.add(calendar.getTime());
}
return evenDates;
} else {
return dates;
}
}
示例7: getAllOrdersCount
public PieChartData getAllOrdersCount(String restaurantId, int kind) {
float[] time;
if (kind == Calendar.DATE) time = new float[24];
else if (kind == Calendar.WEEK_OF_YEAR) time = new float[7];
else time = new float[31];
for (int i = 0; i < time.length; i++) time[i] = 0;
List<String> ordersList = getOrders(restaurantId);
Calendar calendar = Calendar.getInstance();
Order order;
for (String orderKey : ordersList) {
order = orderRepository.get(orderKey);
if (checkTime(order.getDate(), kind)) {
calendar.setTime(order.getDate());
if (kind == Calendar.DATE)
time[calendar.get(Calendar.HOUR_OF_DAY)] += 1.0f;
else if (kind == Calendar.WEEK_OF_YEAR)
time[calendar.get(Calendar.DAY_OF_WEEK)-1] += 1.0f;
else
time[calendar.get(Calendar.DAY_OF_MONTH)] += 1.0f;
}
}
Integer count = 0;
for (float t : time) if (t != 0) ++count;
PieChartData data = new PieChartData(count);
String[] xData = data.getXData();
float[] yData = data.getYData();
Integer j = 0;
for (int i = 0; i < time.length; i++) {
if (time[i] != 0) {
yData[j] = time[i];
String label = "";
if (kind == Calendar.DATE) {
if (i < 10) label += '0';
label += String.valueOf(i) + "h - ";
if (i + 1 < 10) label += '0';
label += String.valueOf(i + 1) + 'h';
} else if (kind == Calendar.WEEK_OF_YEAR) {
if (i == 0) label = "Sunday";
else if (i == 1) label = "Monday";
else if (i == 2) label = "Tuesday";
else if (i == 3) label = "Wednesday";
else if (i == 4) label = "Thursday";
else if (i == 5) label = "Friday";
else if (i == 6) label = "Saturday";
} else {
label = "Day number " + String.valueOf(i) + " of the month.";
}
xData[j] = label;
++j;
}
}
data.setXData(xData);
data.setYData(yData);
return data;
}