Java Code Examples for org.joda.time.DateTimeConstants#MONDAY

The following examples show how to use org.joda.time.DateTimeConstants#MONDAY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Alarm.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
private static int jodaWDToJavaWD(int wd) {
    switch (wd) {
        case DateTimeConstants.MONDAY:
            return Calendar.MONDAY;
        case DateTimeConstants.TUESDAY:
            return Calendar.TUESDAY;
        case DateTimeConstants.WEDNESDAY:
            return Calendar.WEDNESDAY;
        case DateTimeConstants.THURSDAY:
            return Calendar.THURSDAY;
        case DateTimeConstants.FRIDAY:
            return Calendar.FRIDAY;
        case DateTimeConstants.SATURDAY:
            return Calendar.SATURDAY;
        case DateTimeConstants.SUNDAY:
            return Calendar.SUNDAY;
    }
    return 0;
}
 
Example 2
Source File: Alarm.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
private static int jodaWDToJavaWD(int wd) {
    switch (wd) {
        case DateTimeConstants.MONDAY:
            return Calendar.MONDAY;
        case DateTimeConstants.TUESDAY:
            return Calendar.TUESDAY;
        case DateTimeConstants.WEDNESDAY:
            return Calendar.WEDNESDAY;
        case DateTimeConstants.THURSDAY:
            return Calendar.THURSDAY;
        case DateTimeConstants.FRIDAY:
            return Calendar.FRIDAY;
        case DateTimeConstants.SATURDAY:
            return Calendar.SATURDAY;
        case DateTimeConstants.SUNDAY:
            return Calendar.SUNDAY;
    }
    return 0;
}
 
Example 3
Source File: TimeUtils.java    From LQRWeChat with MIT License 5 votes vote down vote up
/**
     * 得到仿微信日期格式输出
     *
     * @param msgTimeMillis
     * @return
     */
    public static String getMsgFormatTime(long msgTimeMillis) {
        DateTime nowTime = new DateTime();
//        LogUtils.sf("nowTime = " + nowTime);
        DateTime msgTime = new DateTime(msgTimeMillis);
//        LogUtils.sf("msgTime = " + msgTime);
        int days = Math.abs(Days.daysBetween(msgTime, nowTime).getDays());
//        LogUtils.sf("days = " + days);
        if (days < 1) {
            //早上、下午、晚上 1:40
            return getTime(msgTime);
        } else if (days == 1) {
            //昨天
            return "昨天 " + getTime(msgTime);
        } else if (days <= 7) {
            //星期
            switch (msgTime.getDayOfWeek()) {
                case DateTimeConstants.SUNDAY:
                    return "周日 " + getTime(msgTime);
                case DateTimeConstants.MONDAY:
                    return "周一 " + getTime(msgTime);
                case DateTimeConstants.TUESDAY:
                    return "周二 " + getTime(msgTime);
                case DateTimeConstants.WEDNESDAY:
                    return "周三 " + getTime(msgTime);
                case DateTimeConstants.THURSDAY:
                    return "周四 " + getTime(msgTime);
                case DateTimeConstants.FRIDAY:
                    return "周五 " + getTime(msgTime);
                case DateTimeConstants.SATURDAY:
                    return "周六 " + getTime(msgTime);
            }
            return "";
        } else {
            //12月22日
            return msgTime.toString("MM月dd日 " + getTime(msgTime));
        }
    }
 
Example 4
Source File: DateTimeFunctions.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns a date a number of workdays away. Saturday and Sundays are not considered working days.
 */
@Function("WORKDAY")
@FunctionParameters({
	@FunctionParameter("dateObject"),
	@FunctionParameter("workdays")})
public Date WORKDAY(Object dateObject, Integer workdays){
	Date convertedDate = convertDateObject(dateObject);
	if(convertedDate==null){
		logCannotConvertToDate();
		return null;
	}
	else{
		boolean lookBack = workdays<0;
		DateTime cursorDT=new DateTime(convertedDate);
		int remainingDays=Math.abs(workdays);
		while(remainingDays>0){
			int dayOfWeek = cursorDT.getDayOfWeek();
			if(!(dayOfWeek==DateTimeConstants.SATURDAY || 
					dayOfWeek==DateTimeConstants.SUNDAY)){
				// Decrement remaining days only when it is not Saturday or Sunday
				remainingDays--;
			}
			if(!lookBack) {
				cursorDT= dayOfWeek==DateTimeConstants.FRIDAY?cursorDT.plusDays(3):cursorDT.plusDays(1);
			}
			else {
				cursorDT= dayOfWeek==DateTimeConstants.MONDAY?cursorDT.minusDays(3):cursorDT.minusDays(1);
			}
		}
		return cursorDT.toDate();
	}
}
 
Example 5
Source File: TestGJChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testSubtractDays() {
    // This is a test for a bug in version 1.0. The dayOfMonth range
    // duration field did not match the monthOfYear duration field. This
    // caused an exception to be thrown when subtracting days.
    DateTime dt = new DateTime
        (1112306400000L, GJChronology.getInstance(DateTimeZone.forID("Europe/Berlin")));
    YearMonthDay ymd = dt.toYearMonthDay();
    while (ymd.toDateTimeAtMidnight().getDayOfWeek() != DateTimeConstants.MONDAY) { 
        ymd = ymd.minus(Period.days(1));
    }
}
 
Example 6
Source File: TestGJChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testSubtractDays() {
    // This is a test for a bug in version 1.0. The dayOfMonth range
    // duration field did not match the monthOfYear duration field. This
    // caused an exception to be thrown when subtracting days.
    DateTime dt = new DateTime
        (1112306400000L, GJChronology.getInstance(DateTimeZone.forID("Europe/Berlin")));
    YearMonthDay ymd = dt.toYearMonthDay();
    while (ymd.toDateTimeAtMidnight().getDayOfWeek() != DateTimeConstants.MONDAY) { 
        ymd = ymd.minus(Period.days(1));
    }
}
 
Example 7
Source File: BiWeeklyPeriodFilter.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static DateTime getStartDayOfFirstBiWeek(DateTime date){
    LocalDate localDate = new LocalDate( date.getYear(), date.getMonthOfYear(), 1 );
    while ( localDate.getDayOfWeek() != DateTimeConstants.MONDAY ) {
        localDate = localDate.plusDays( 1 );
    }
    return localDate.toDateTimeAtStartOfDay();
}
 
Example 8
Source File: GeolocationXmlReportGenerator.java    From megatron-java with Apache License 2.0 5 votes vote down vote up
private DateTime startDateTime(int noOfWeeks) {
    // find first monday 
    DateTime result = new DateTime();
    while (true) {
        if (result.getDayOfWeek() == DateTimeConstants.MONDAY) {
            break;
        }
        result = result.minusDays(1);
    }
    return result.minusDays(7*noOfWeeks);
}
 
Example 9
Source File: StatisticsXmlReportGenerator.java    From megatron-java with Apache License 2.0 5 votes vote down vote up
private DateTime startDateTime(int noOfWeeks) {
    // find first monday 
    DateTime result = new DateTime();
    while (true) {
        if (result.getDayOfWeek() == DateTimeConstants.MONDAY) {
            break;
        }
        result = result.minusDays(1);
    }
    return result.minusDays(7*noOfWeeks);
}
 
Example 10
Source File: TimePeriod.java    From megatron-java with Apache License 2.0 5 votes vote down vote up
/**
 * Returns date for monday in specified week.
 *  
 * @param weekStr full week string, e.g. "2010-01" (which will return 2010-01-04).
 */
private DateTime parseIsoWeek(String weekStr) throws Exception {
    DateTime result = null;
    
    // Split year and week
    String[] headTail = StringUtil.splitHeadTail(weekStr, "-", false);
    if ((headTail == null) || StringUtil.isNullOrEmpty(headTail[0]) || StringUtil.isNullOrEmpty(headTail[1]) || (headTail[0].length() != 4)) {
        throw new Exception("Invalid week string: " + weekStr);
    }

    // Get monday of week 1.
    // The first week of a year is the one that includes the first Thursday of the year.
    // http://www.fourmilab.ch/documents/calendar/
    // http://joda-time.sourceforge.net/cal_iso.html
    String day1InYear = headTail[0] + "-01-01";
    DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd");
    result = fmt.parseDateTime(day1InYear);
    if (result.getDayOfWeek() <= DateTimeConstants.THURSDAY) {
        while (result.getDayOfWeek() != DateTimeConstants.MONDAY) {
            result = result.minusDays(1);
        }
    } else {
        while (result.getDayOfWeek() != DateTimeConstants.MONDAY) {
            result = result.plusDays(1);
        }
    }

    // Add week number
    int week = Integer.parseInt(headTail[1]);
    if ((week < 1) || (week > 53)) {
        throw new Exception("Invalid week string: " + weekStr);
    }
    result = result.plusDays(7*(week-1));
    
    return result;
}
 
Example 11
Source File: DayOfWeekFromSundayDateTimeField.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Get the minimum value that this field can have.
 *
 * @return the field's minimum value
 */
@Override
public int getMinimumValue() {
  // returns 1 which corresponds to SUNDAY for this impl
  return DateTimeConstants.MONDAY;
}
 
Example 12
Source File: BiWeeklyExpiryDayValidator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected int weekStarts() {
    return DateTimeConstants.MONDAY;
}
 
Example 13
Source File: WeeklyExpiryDayValidator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected int weekStarts() {
    return DateTimeConstants.MONDAY;
}
 
Example 14
Source File: Jodatime.java    From maven-framework-project with MIT License 4 votes vote down vote up
private static void getTimeInfo(){
	
	System.out.println("-------------获取当前时间-----------------");
	
	String weekStr="";
	
	DateTime dt = new DateTime();
	//年
	int year = dt.getYear();
	//月
	int month = dt.getMonthOfYear();
	//日
	int day = dt.getDayOfMonth();
	//星期
	int week = dt.getDayOfWeek();
	//点
	int hour = dt.getHourOfDay();
	//分
	int min = dt.getMinuteOfHour();
	//秒
	int sec = dt.getSecondOfMinute();
	//毫秒
	int msec = dt.getMillisOfSecond();
	
	//星期
	switch(week) {
	case DateTimeConstants.SUNDAY:
		weekStr = "星期日";
		System.out.println(weekStr);
		break;
	case DateTimeConstants.MONDAY:
		weekStr = "星期一";
		System.out.println(weekStr);
		break;
	case DateTimeConstants.TUESDAY:
		weekStr = "星期二";
		System.out.println(weekStr);
		break;
	case DateTimeConstants.WEDNESDAY:
		weekStr = "星期三";
		System.out.println(weekStr);
		break;
	case DateTimeConstants.THURSDAY:
		weekStr = "星期四";
		System.out.println(weekStr);
		break;
	case DateTimeConstants.FRIDAY:
		weekStr = "星期五";
		System.out.println(weekStr);
		break;
	case DateTimeConstants.SATURDAY:
		weekStr = "星期六";
		System.out.println(weekStr);
		break;
	}
	
	System.out.println(year + "/" + month + "/" + day + " " + hour + ":" + min + ":" + sec + ":" + msec + " " + weekStr);
	
}
 
Example 15
Source File: GJDayOfWeekDateTimeField.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get the minimum value that this field can have.
 * 
 * @return the field's minimum value
 */
public int getMinimumValue() {
    return DateTimeConstants.MONDAY;
}
 
Example 16
Source File: GJDayOfWeekDateTimeField.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get the minimum value that this field can have.
 * 
 * @return the field's minimum value
 */
public int getMinimumValue() {
    return DateTimeConstants.MONDAY;
}