List of usage examples for org.joda.time DateTime dayOfWeek
public Property dayOfWeek()
From source file:net.sourceforge.fenixedu.util.WeekDay.java
License:Open Source License
public static WeekDay fromJodaTimeToWeekDay(final DateTime date) { final int dayOfWeek = date.dayOfWeek().get(); switch (dayOfWeek) { case 1:/*from ww w . j av a 2 s .c o m*/ return WeekDay.MONDAY; case 2: return WeekDay.TUESDAY; case 3: return WeekDay.WEDNESDAY; case 4: return WeekDay.THURSDAY; case 5: return WeekDay.FRIDAY; case 6: return WeekDay.SATURDAY; case 7: return WeekDay.SUNDAY; default: return null; } }
From source file:nl.welteninstituut.tel.la.importers.ImportTask.java
License:Open Source License
/** * Checks if the specified time is allowed according to the configuration * settings./*from w w w.java2s .co m*/ * * @param dateTime * the date time * @return true, if is time allowed */ protected boolean isTimeAllowed(final DateTime dateTime) { if (useWorkingDays && dateTime.dayOfWeek().get() > 5) { return false; } LocalTime time = dateTime.toLocalTime(); if (starttime != null && time.isBefore(starttime)) { return false; } if (endtime != null && time.isAfter(endtime)) { return false; } return true; }
From source file:org.apache.druid.query.expression.TimestampExtractExprMacro.java
License:Apache License
@Override public Expr apply(final List<Expr> args) { if (args.size() < 2 || args.size() > 3) { throw new IAE("Function[%s] must have 2 to 3 arguments", name()); }/*from ww w.ja v a 2 s. c o m*/ if (!args.get(1).isLiteral() || args.get(1).getLiteralValue() == null) { throw new IAE("Function[%s] unit arg must be literal", name()); } if (args.size() > 2 && !args.get(2).isLiteral()) { throw new IAE("Function[%s] timezone arg must be literal", name()); } final Expr arg = args.get(0); final Unit unit = Unit.valueOf(StringUtils.toUpperCase((String) args.get(1).getLiteralValue())); final DateTimeZone timeZone; if (args.size() > 2) { timeZone = ExprUtils.toTimeZone(args.get(2)); } else { timeZone = DateTimeZone.UTC; } final ISOChronology chronology = ISOChronology.getInstance(timeZone); class TimestampExtractExpr extends ExprMacroTable.BaseScalarUnivariateMacroFunctionExpr { private TimestampExtractExpr(Expr arg) { super(arg); } @Nonnull @Override public ExprEval eval(final ObjectBinding bindings) { Object val = arg.eval(bindings).value(); if (val == null) { // Return null if the argument if null. return ExprEval.of(null); } final DateTime dateTime = new DateTime(val, chronology); long epoch = dateTime.getMillis() / 1000; switch (unit) { case EPOCH: return ExprEval.of(epoch); case MICROSECOND: return ExprEval.of(epoch / 1000); case MILLISECOND: return ExprEval.of(dateTime.millisOfSecond().get()); case SECOND: return ExprEval.of(dateTime.secondOfMinute().get()); case MINUTE: return ExprEval.of(dateTime.minuteOfHour().get()); case HOUR: return ExprEval.of(dateTime.hourOfDay().get()); case DAY: return ExprEval.of(dateTime.dayOfMonth().get()); case DOW: return ExprEval.of(dateTime.dayOfWeek().get()); case ISODOW: return ExprEval.of(dateTime.dayOfWeek().get()); case DOY: return ExprEval.of(dateTime.dayOfYear().get()); case WEEK: return ExprEval.of(dateTime.weekOfWeekyear().get()); case MONTH: return ExprEval.of(dateTime.monthOfYear().get()); case QUARTER: return ExprEval.of((dateTime.monthOfYear().get() - 1) / 3 + 1); case YEAR: return ExprEval.of(dateTime.year().get()); case ISOYEAR: return ExprEval.of(dateTime.year().get()); case DECADE: // The year field divided by 10, See https://www.postgresql.org/docs/10/functions-datetime.html return ExprEval.of(Math.floor(dateTime.year().get() / 10)); case CENTURY: return ExprEval.of(dateTime.centuryOfEra().get() + 1); case MILLENNIUM: // Years in the 1900s are in the second millennium. The third millennium started January 1, 2001. // See https://www.postgresql.org/docs/10/functions-datetime.html return ExprEval.of(Math.round(Math.ceil(dateTime.year().get() / 1000))); default: throw new ISE("Unhandled unit[%s]", unit); } } @Override public Expr visit(Shuttle shuttle) { Expr newArg = arg.visit(shuttle); return shuttle.visit(new TimestampExtractExpr(newArg)); } } return new TimestampExtractExpr(arg); }
From source file:org.apache.pig.piggybank.evaluation.datetime.truncate.ISOToWeek.java
License:Apache License
@Override public String exec(Tuple input) throws IOException { if (input == null || input.size() < 1) { return null; }//w w w. ja v a 2 s .com DateTime dt = ISOHelper.parseDateTime(input); // Set the the day to 1, and the hour, minute, second and milliseconds to 0 DateTime result = dt.dayOfWeek().setCopy(1).hourOfDay().setCopy(0).minuteOfHour().setCopy(0) .secondOfMinute().setCopy(0).millisOfSecond().setCopy(0); return result.toString(); }
From source file:org.joda.example.time.Examples.java
License:Apache License
private void runDateTime() { System.out.println("DateTime"); System.out.println("======="); System.out.println(//from w w w.j a v a2 s . c om "DateTime stores a the date and time using millisecs from 1970-01-01T00:00:00Z internally"); System.out.println("DateTime is immutable and thread-safe"); System.out.println(" in = new DateTime()"); DateTime in = new DateTime(); System.out.println("Millisecond time: in.getMillis(): " + in.getMillis()); System.out.println("ISO string version: in.toString(): " + in.toString()); System.out.println("ISO chronology: in.getChronology(): " + in.getChronology()); System.out.println("Your time zone: in.getDateTimeZone(): " + in.getZone()); System.out.println("Change millis: in.withMillis(0): " + in.withMillis(0L)); System.out.println(""); System.out.println("Get year: in.getYear(): " + in.getYear()); System.out.println("Get monthOfYear: in.getMonthOfYear(): " + in.getMonthOfYear()); System.out.println("Get dayOfMonth: in.getDayOfMonth(): " + in.getDayOfMonth()); System.out.println("..."); System.out.println("Property access: in.dayOfWeek().get(): " + in.dayOfWeek().get()); System.out.println( "Day of week as text: in.dayOfWeek().getAsText(): " + in.dayOfWeek().getAsText()); System.out.println( "Day as short text: in.dayOfWeek().getAsShortText(): " + in.dayOfWeek().getAsShortText()); System.out.println("Day in french: in.dayOfWeek().getAsText(Locale.FRENCH):" + in.dayOfWeek().getAsText(Locale.FRENCH)); System.out.println("Max allowed value: in.dayOfWeek().getMaximumValue(): " + in.dayOfWeek().getMaximumValue()); System.out.println("Min allowed value: in.dayOfWeek().getMinimumValue(): " + in.dayOfWeek().getMinimumValue()); System.out.println( "Copy & set to Jan: in.monthOfYear().setCopy(1): " + in.monthOfYear().setCopy(1)); System.out.println( "Copy & add 14 months: in.monthOfYear().addCopy(14): " + in.monthOfYear().addToCopy(14)); System.out.println("Add 14 mnths in field:in.monthOfYear().addWrapFieldCopy(14): " + in.monthOfYear().addWrapFieldToCopy(14)); System.out.println("..."); System.out.println("Convert to Instant: in.toInstant(): " + in.toInstant()); System.out.println("Convert to DateTime: in.toDateTime(): " + in.toDateTime()); System.out.println("Convert to MutableDT: in.toMutableDateTime(): " + in.toMutableDateTime()); System.out.println("Convert to Date: in.toDate(): " + in.toDate()); System.out.println("Convert to Calendar: in.toCalendar(Locale.UK): " + in.toCalendar(Locale.UK).toString().substring(0, 46)); System.out.println("Convert to GregCal: in.toGregorianCalendar(): " + in.toGregorianCalendar().toString().substring(0, 46)); System.out.println(""); System.out.println(" in2 = new DateTime(in.getMillis() + 10)"); DateTime in2 = new DateTime(in.getMillis() + 10); System.out.println("Equals ms and chrono: in.equals(in2): " + in.equals(in2)); System.out.println("Compare millisecond: in.compareTo(in2): " + in.compareTo(in2)); System.out.println("Compare millisecond: in.isEqual(in2): " + in.isEqual(in2)); System.out.println("Compare millisecond: in.isAfter(in2): " + in.isAfter(in2)); System.out.println("Compare millisecond: in.isBefore(in2): " + in.isBefore(in2)); }
From source file:org.jpos.qi.components.DateRange.java
License:Open Source License
private static Map<String, Date> createStartDateMap() { QI app = (QI) UI.getCurrent();/*from ww w. j a va2s . c o m*/ DateTime dt = DateTime.now().millisOfDay().withMinimumValue(); Map<String, Date> map = new HashMap<>(); map.put(LAST_HOUR, DateTime.now().minusHours(1).toDate()); map.put(TODAY, dt.toDate()); map.put(YESTERDAY, dt.minusDays(1).toDate()); map.put(THIS_WEEK, dt.dayOfWeek().withMinimumValue().toDate()); map.put(LAST_WEEK, dt.dayOfWeek().withMinimumValue().minusWeeks(1).toDate()); map.put(THIS_MONTH, dt.dayOfMonth().withMinimumValue().toDate()); map.put(LAST_MONTH, dt.dayOfMonth().withMinimumValue().minusMonths(1).toDate()); map.put(THIS_YEAR, dt.dayOfYear().withMinimumValue().toDate()); map.put(ALL_TIME, null); return map; }
From source file:org.jpos.qi.components.DateRange.java
License:Open Source License
private static Map<String, Date> createEndDateMap() { QI app = (QI) UI.getCurrent();//from w w w .j a v a2 s . c o m DateTime dt = DateTime.now().millisOfDay().withMaximumValue(); Map<String, Date> map = new HashMap<>(); map.put(LAST_HOUR, DateTime.now().toDate()); map.put(TODAY, dt.toDate()); map.put(YESTERDAY, dt.minusDays(1).toDate()); map.put(THIS_WEEK, dt.dayOfWeek().withMaximumValue().toDate()); map.put(LAST_WEEK, dt.dayOfWeek().withMaximumValue().minusWeeks(1).toDate()); map.put(THIS_MONTH, dt.dayOfMonth().withMaximumValue().toDate()); map.put(LAST_MONTH, dt.dayOfMonth().withMaximumValue().minusMonths(1).toDate()); map.put(THIS_YEAR, dt.dayOfYear().withMaximumValue().toDate()); map.put(ALL_TIME, null); return map; }
From source file:org.mifos.calendar.WorkingDay.java
License:Open Source License
public static boolean isWorkingDay(final DateTime day, final List<Days> workingDays) { return workingDays.contains(Days.days(day.dayOfWeek().get())); }
From source file:org.mifos.dmt.business.Meetings.schedule.Schedule.java
License:Open Source License
protected DateTime getWorkingDay(DateTime meetingDate) { int iDoW;// ww w. j a va2 s.co m iDoW = meetingDate.dayOfWeek().get(); while (iDoW == 7) { meetingDate = meetingDate.plusDays(1); iDoW = meetingDate.dayOfWeek().get(); } return meetingDate; }
From source file:org.sonar.plugins.scmstats.measures.ChangeLogHandler.java
License:Open Source License
public void generateMeasures() { for (ChangeLogInfo changeLogInfo : changeLogs) { if (!ignoredAuthors.contains(changeLogInfo.getAuthor())) { commitsPerUser = updateAuthorActivity(commitsPerUser, changeLogInfo); DateTime dt = new DateTime(changeLogInfo.getCommitDate()); commitsPerClockHour = MapUtils.updateMap(commitsPerClockHour, String.format("%2d", dt.getHourOfDay()).replace(' ', '0')); commitsPerWeekDay = MapUtils.updateMap(commitsPerWeekDay, dt.dayOfWeek().getAsString()); commitsPerMonth = MapUtils.updateMap(commitsPerMonth, String.format("%2d", dt.getMonthOfYear()).replace(' ', '0')); }//from w w w .j a va 2 s.co m } }