List of usage examples for org.joda.time DateTime getDayOfMonth
public int getDayOfMonth()
From source file:org.jruby.ext.jvyaml.JRubyConstructor.java
public static Object constructYamlTimestampYMD(final Constructor ctor, final Node node) { DateTime dt = (DateTime) (((Object[]) SafeConstructorImpl.constructYamlTimestamp(ctor, node))[0]); Ruby runtime = ((JRubyConstructor) ctor).runtime; return RuntimeHelpers.invoke(runtime.getCurrentContext(), runtime.fastGetClass("Date"), "new", runtime.newFixnum(dt.getYear()), runtime.newFixnum(dt.getMonthOfYear()), runtime.newFixnum(dt.getDayOfMonth())); }
From source file:org.jruby.CompatVersion.java
License:LGPL
public RubyObject mdump(final IRubyObject[] args) { RubyTime obj = (RubyTime) args[0]; DateTime dateTime = obj.dt.withZone(DateTimeZone.UTC); byte dumpValue[] = new byte[8]; int pe = 0x1 << 31 | (dateTime.getYear() - 1900) << 14 | (dateTime.getMonthOfYear() - 1) << 10 | dateTime.getDayOfMonth() << 5 | dateTime.getHourOfDay(); int se = dateTime.getMinuteOfHour() << 26 | dateTime.getSecondOfMinute() << 20 | (dateTime.getMillisOfSecond() * 1000 + (int) usec); // dump usec, not msec for (int i = 0; i < 4; i++) { dumpValue[i] = (byte) (pe & 0xFF); pe >>>= 8;/*from ww w.j a v a2 s.c o m*/ } for (int i = 4; i < 8; i++) { dumpValue[i] = (byte) (se & 0xFF); se >>>= 8; } return RubyString.newString(obj.getRuntime(), new ByteList(dumpValue, false)); }
From source file:org.jruby.RubyTime.java
License:LGPL
public RubyObject mdump() { Ruby runtime = getRuntime();/*from w w w .ja va 2 s . com*/ RubyTime obj = this; DateTime dateTime = obj.dt.toDateTime(DateTimeZone.UTC); byte dumpValue[] = new byte[8]; long nanos = this.nsec; long usec = this.nsec / 1000; long nanosec = this.nsec % 1000; int pe = 0x1 << 31 | ((obj.gmt().isTrue()) ? 0x1 : 0x0) << 30 | (dateTime.getYear() - 1900) << 14 | (dateTime.getMonthOfYear() - 1) << 10 | dateTime.getDayOfMonth() << 5 | dateTime.getHourOfDay(); int se = dateTime.getMinuteOfHour() << 26 | dateTime.getSecondOfMinute() << 20 | (dateTime.getMillisOfSecond() * 1000 + (int) usec); // dump usec, not msec for (int i = 0; i < 4; i++) { dumpValue[i] = (byte) (pe & 0xFF); pe >>>= 8; } for (int i = 4; i < 8; i++) { dumpValue[i] = (byte) (se & 0xFF); se >>>= 8; } RubyString string = RubyString.newString(obj.getRuntime(), new ByteList(dumpValue)); // 1.9 includes more nsecs copyInstanceVariablesInto(string); // nanos in numerator/denominator form if (nanosec != 0) { string.setInternalVariable("nano_num", runtime.newFixnum(nanosec)); string.setInternalVariable("nano_den", runtime.newFixnum(1)); } // submicro for 1.9.1 compat byte[] submicro = new byte[2]; int len = 2; submicro[1] = (byte) ((nanosec % 10) << 4); nanosec /= 10; submicro[0] = (byte) (nanosec % 10); nanosec /= 10; submicro[0] |= (byte) ((nanosec % 10) << 4); if (submicro[1] == 0) len = 1; string.setInternalVariable("submicro", RubyString.newString(runtime, submicro, 0, len)); // time zone if (dt.getZone() != DateTimeZone.UTC) { long offset = dt.getZone().getOffset(dt.getMillis()); string.setInternalVariable("offset", runtime.newFixnum(offset / 1000)); String zone = dt.getZone().getShortName(dt.getMillis()); if (!TIME_OFFSET_PATTERN.matcher(zone).matches()) { string.setInternalVariable("zone", runtime.newString(zone)); } } return string; }
From source file:org.jruby.truffle.core.time.RubyDateFormatter.java
License:LGPL
public ByteList formatToByteList(List<Token> compiledPattern, DateTime dt, long nsec) { RubyTimeOutputFormatter formatter = RubyTimeOutputFormatter.DEFAULT_FORMATTER; ByteList toAppendTo = new ByteList(); for (Token token : compiledPattern) { String output = null;/*w w w.j ava 2 s .c om*/ long value = 0; FieldType type = TEXT; Format format = token.getFormat(); switch (format) { case FORMAT_ENCODING: toAppendTo.setEncoding((Encoding) token.getData()); continue; // go to next token case FORMAT_OUTPUT: formatter = (RubyTimeOutputFormatter) token.getData(); continue; // go to next token case FORMAT_STRING: output = token.getData().toString(); break; case FORMAT_WEEK_LONG: // This is GROSS, but Java API's aren't ISO 8601 compliant at all int v = (dt.getDayOfWeek() + 1) % 8; if (v == 0) { v++; } output = FORMAT_SYMBOLS.getWeekdays()[v]; break; case FORMAT_WEEK_SHORT: // This is GROSS, but Java API's aren't ISO 8601 compliant at all v = (dt.getDayOfWeek() + 1) % 8; if (v == 0) { v++; } output = FORMAT_SYMBOLS.getShortWeekdays()[v]; break; case FORMAT_MONTH_LONG: output = FORMAT_SYMBOLS.getMonths()[dt.getMonthOfYear() - 1]; break; case FORMAT_MONTH_SHORT: output = FORMAT_SYMBOLS.getShortMonths()[dt.getMonthOfYear() - 1]; break; case FORMAT_DAY: type = NUMERIC2; value = dt.getDayOfMonth(); break; case FORMAT_DAY_S: type = NUMERIC2BLANK; value = dt.getDayOfMonth(); break; case FORMAT_HOUR: type = NUMERIC2; value = dt.getHourOfDay(); break; case FORMAT_HOUR_BLANK: type = NUMERIC2BLANK; value = dt.getHourOfDay(); break; case FORMAT_HOUR_M: case FORMAT_HOUR_S: value = dt.getHourOfDay(); if (value == 0) { value = 12; } else if (value > 12) { value -= 12; } type = (format == Format.FORMAT_HOUR_M) ? NUMERIC2 : NUMERIC2BLANK; break; case FORMAT_DAY_YEAR: type = NUMERIC3; value = dt.getDayOfYear(); break; case FORMAT_MINUTES: type = NUMERIC2; value = dt.getMinuteOfHour(); break; case FORMAT_MONTH: type = NUMERIC2; value = dt.getMonthOfYear(); break; case FORMAT_MERIDIAN: output = dt.getHourOfDay() < 12 ? "AM" : "PM"; break; case FORMAT_MERIDIAN_LOWER_CASE: output = dt.getHourOfDay() < 12 ? "am" : "pm"; break; case FORMAT_SECONDS: type = NUMERIC2; value = dt.getSecondOfMinute(); break; case FORMAT_WEEK_YEAR_M: type = NUMERIC2; value = formatWeekYear(dt, Calendar.MONDAY); break; case FORMAT_WEEK_YEAR_S: type = NUMERIC2; value = formatWeekYear(dt, Calendar.SUNDAY); break; case FORMAT_DAY_WEEK: type = NUMERIC; value = dt.getDayOfWeek() % 7; break; case FORMAT_DAY_WEEK2: type = NUMERIC; value = dt.getDayOfWeek(); break; case FORMAT_YEAR_LONG: value = year(dt, dt.getYear()); type = (value >= 0) ? NUMERIC4 : NUMERIC5; break; case FORMAT_YEAR_SHORT: type = NUMERIC2; value = year(dt, dt.getYear()) % 100; break; case FORMAT_COLON_ZONE_OFF: // custom logic because this is so weird value = dt.getZone().getOffset(dt.getMillis()) / 1000; int colons = (Integer) token.getData(); output = formatZone(colons, (int) value, formatter); break; case FORMAT_ZONE_ID: output = getRubyTimeZoneName(dt); break; case FORMAT_CENTURY: type = NUMERIC; value = year(dt, dt.getYear()) / 100; break; case FORMAT_EPOCH: type = NUMERIC; value = dt.getMillis() / 1000; break; case FORMAT_WEEK_WEEKYEAR: type = NUMERIC2; value = dt.getWeekOfWeekyear(); break; case FORMAT_MILLISEC: case FORMAT_NANOSEC: int defaultWidth = (format == Format.FORMAT_NANOSEC) ? 9 : 3; int width = formatter.getWidth(defaultWidth); output = RubyTimeOutputFormatter.formatNumber(dt.getMillisOfSecond(), 3, '0'); if (width > 3) { output += RubyTimeOutputFormatter.formatNumber(nsec, 6, '0'); } if (width < output.length()) { output = output.substring(0, width); } else { // Not enough precision, fill with 0 while (output.length() < width) output += "0"; } formatter = RubyTimeOutputFormatter.DEFAULT_FORMATTER; // no more formatting break; case FORMAT_WEEKYEAR: value = year(dt, dt.getWeekyear()); type = (value >= 0) ? NUMERIC4 : NUMERIC5; break; case FORMAT_WEEKYEAR_SHORT: type = NUMERIC2; value = year(dt, dt.getWeekyear()) % 100; break; case FORMAT_MICROSEC_EPOCH: // only available for Date type = NUMERIC; value = dt.getMillis(); break; case FORMAT_SPECIAL: throw new Error("FORMAT_SPECIAL is a special token only for the lexer."); } try { output = formatter.format(output, value, type); } catch (IndexOutOfBoundsException ioobe) { throw new RaiseException( context.getCoreExceptions().errnoError(Errno.ERANGE.intValue(), "strftime", currentNode)); } // reset formatter formatter = RubyTimeOutputFormatter.DEFAULT_FORMATTER; toAppendTo.append( output.getBytes(context.getEncodingManager().charsetForEncoding(toAppendTo.getEncoding()))); } return toAppendTo; }
From source file:org.jruby.util.RubyDateFormatter.java
License:LGPL
public ByteList formatToByteList(List<Token> compiledPattern, DateTime dt, long nsec, IRubyObject sub_millis) { RubyTimeOutputFormatter formatter = RubyTimeOutputFormatter.DEFAULT_FORMATTER; ByteList toAppendTo = new ByteList(); for (Token token : compiledPattern) { String output = null;/*from w w w . j a v a2 s.c o m*/ long value = 0; FieldType type = TEXT; Format format = token.getFormat(); switch (format) { case FORMAT_ENCODING: toAppendTo.setEncoding((Encoding) token.getData()); continue; // go to next token case FORMAT_OUTPUT: formatter = (RubyTimeOutputFormatter) token.getData(); continue; // go to next token case FORMAT_STRING: output = token.getData().toString(); break; case FORMAT_WEEK_LONG: // This is GROSS, but Java API's aren't ISO 8601 compliant at all int v = (dt.getDayOfWeek() + 1) % 8; if (v == 0) { v++; } output = FORMAT_SYMBOLS.getWeekdays()[v]; break; case FORMAT_WEEK_SHORT: // This is GROSS, but Java API's aren't ISO 8601 compliant at all v = (dt.getDayOfWeek() + 1) % 8; if (v == 0) { v++; } output = FORMAT_SYMBOLS.getShortWeekdays()[v]; break; case FORMAT_MONTH_LONG: output = FORMAT_SYMBOLS.getMonths()[dt.getMonthOfYear() - 1]; break; case FORMAT_MONTH_SHORT: output = FORMAT_SYMBOLS.getShortMonths()[dt.getMonthOfYear() - 1]; break; case FORMAT_DAY: type = NUMERIC2; value = dt.getDayOfMonth(); break; case FORMAT_DAY_S: type = NUMERIC2BLANK; value = dt.getDayOfMonth(); break; case FORMAT_HOUR: type = NUMERIC2; value = dt.getHourOfDay(); break; case FORMAT_HOUR_BLANK: type = NUMERIC2BLANK; value = dt.getHourOfDay(); break; case FORMAT_HOUR_M: case FORMAT_HOUR_S: value = dt.getHourOfDay(); if (value == 0) { value = 12; } else if (value > 12) { value -= 12; } type = (format == Format.FORMAT_HOUR_M) ? NUMERIC2 : NUMERIC2BLANK; break; case FORMAT_DAY_YEAR: type = NUMERIC3; value = dt.getDayOfYear(); break; case FORMAT_MINUTES: type = NUMERIC2; value = dt.getMinuteOfHour(); break; case FORMAT_MONTH: type = NUMERIC2; value = dt.getMonthOfYear(); break; case FORMAT_MERIDIAN: output = dt.getHourOfDay() < 12 ? "AM" : "PM"; break; case FORMAT_MERIDIAN_LOWER_CASE: output = dt.getHourOfDay() < 12 ? "am" : "pm"; break; case FORMAT_SECONDS: type = NUMERIC2; value = dt.getSecondOfMinute(); break; case FORMAT_WEEK_YEAR_M: type = NUMERIC2; value = formatWeekYear(dt, java.util.Calendar.MONDAY); break; case FORMAT_WEEK_YEAR_S: type = NUMERIC2; value = formatWeekYear(dt, java.util.Calendar.SUNDAY); break; case FORMAT_DAY_WEEK: type = NUMERIC; value = dt.getDayOfWeek() % 7; break; case FORMAT_DAY_WEEK2: type = NUMERIC; value = dt.getDayOfWeek(); break; case FORMAT_YEAR_LONG: value = year(dt, dt.getYear()); type = (value >= 0) ? NUMERIC4 : NUMERIC5; break; case FORMAT_YEAR_SHORT: type = NUMERIC2; value = year(dt, dt.getYear()) % 100; break; case FORMAT_COLON_ZONE_OFF: // custom logic because this is so weird value = dt.getZone().getOffset(dt.getMillis()) / 1000; int colons = (Integer) token.getData(); output = formatZone(colons, (int) value, formatter); break; case FORMAT_ZONE_ID: output = dt.getZone().getShortName(dt.getMillis()); break; case FORMAT_CENTURY: type = NUMERIC; value = year(dt, dt.getYear()) / 100; break; case FORMAT_EPOCH: type = NUMERIC; value = dt.getMillis() / 1000; break; case FORMAT_WEEK_WEEKYEAR: type = NUMERIC2; value = dt.getWeekOfWeekyear(); break; case FORMAT_MILLISEC: case FORMAT_NANOSEC: int defaultWidth = (format == Format.FORMAT_NANOSEC) ? 9 : 3; int width = formatter.getWidth(defaultWidth); output = RubyTimeOutputFormatter.formatNumber(dt.getMillisOfSecond(), 3, '0'); if (width > 3) { if (sub_millis == null || sub_millis.isNil()) { // Time output += RubyTimeOutputFormatter.formatNumber(nsec, 6, '0'); } else { // Date, DateTime int prec = width - 3; IRubyObject power = context.runtime.newFixnum(10).callMethod("**", context.runtime.newFixnum(prec)); IRubyObject truncated = sub_millis.callMethod(context, "numerator").callMethod(context, "*", power); truncated = truncated.callMethod(context, "/", sub_millis.callMethod(context, "denominator")); long decimals = truncated.convertToInteger().getLongValue(); output += RubyTimeOutputFormatter.formatNumber(decimals, prec, '0'); } } if (width < output.length()) { output = output.substring(0, width); } else { // Not enough precision, fill with 0 while (output.length() < width) output += "0"; } formatter = RubyTimeOutputFormatter.DEFAULT_FORMATTER; // no more formatting break; case FORMAT_WEEKYEAR: value = year(dt, dt.getWeekyear()); type = (value >= 0) ? NUMERIC4 : NUMERIC5; break; case FORMAT_WEEKYEAR_SHORT: type = NUMERIC2; value = year(dt, dt.getWeekyear()) % 100; break; case FORMAT_MICROSEC_EPOCH: // only available for Date type = NUMERIC; value = dt.getMillis(); break; case FORMAT_SPECIAL: throw new Error("FORMAT_SPECIAL is a special token only for the lexer."); } output = formatter.format(output, value, type); // reset formatter formatter = RubyTimeOutputFormatter.DEFAULT_FORMATTER; toAppendTo.append(output .getBytes(context.runtime.getEncodingService().charsetForEncoding(toAppendTo.getEncoding()))); } return toAppendTo; }
From source file:org.jtotus.common.DayisHoliday.java
License:Open Source License
public static boolean isHoliday(DateTime date) { if (date == null || date.getDayOfWeek() == DateTimeConstants.SATURDAY || date.getDayOfWeek() == DateTimeConstants.SUNDAY) { return true; }//from w w w .j ava 2 s . co m //int toSearch = date.get(Calendar.DATE)*1000000+(date.get(Calendar.MONTH)+1)*10000+date.get(Calendar.YEAR); int toSearch = date.getDayOfMonth() * 1000000 + date.getMonthOfYear() * 10000 + date.getYear(); //System.out.printf("To search:%d == %d:%d:%d\n", toSearch, date.get(Calendar.DATE), date.get(Calendar.MONTH)+1, date.get(Calendar.YEAR)); for (int day : days) { if (day == toSearch) { return true; } } return false; }
From source file:org.jtotus.database.LocalJDBC.java
License:Open Source License
public double[] fetchPeriod(String tableName, DateTime startDate, DateTime endDate, String type) { BigDecimal retValue = null;/* w w w. j a v a2 s . c o m*/ PreparedStatement pstm = null; java.sql.Date retDate = null; ResultSet results = null; ArrayList<Double> closingPrices = new ArrayList<Double>(600); Connection connection = null; try { String query = "SELECT " + type + ", DATE FROM " + this.normTableName(tableName) + " WHERE DATE>=? AND DATE<=? ORDER BY DATE ASC"; // this.createTable(connection, this.normTableName(tableName)); connection = this.getConnection(); pstm = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); java.sql.Date startSqlDate = new java.sql.Date(startDate.getMillis()); pstm.setDate(1, startSqlDate); java.sql.Date endSqlDate = new java.sql.Date(endDate.getMillis()); pstm.setDate(2, endSqlDate); DateIterator dateIter = new DateIterator(startDate, endDate); results = pstm.executeQuery(); DateTime dateCheck; if (debug) { System.out.printf("start data %s end date: %s\n", startSqlDate.toString(), endSqlDate.toString()); } while (dateIter.hasNext()) { dateCheck = dateIter.nextInCalendar(); if (results.next()) { retValue = results.getBigDecimal(1); retDate = results.getDate(2); DateTime compCal = new DateTime(retDate.getTime()); if (compCal.getDayOfMonth() == dateCheck.getDayOfMonth() && compCal.getMonthOfYear() == dateCheck.getMonthOfYear() && compCal.getYear() == dateCheck.getYear()) { closingPrices.add(retValue.doubleValue()); continue; } else { results.previous(); } } BigDecimal failOverValue = getFetcher().fetchData(tableName, dateCheck, type); if (failOverValue != null) { closingPrices.add(failOverValue.doubleValue()); } } } catch (SQLException ex) { System.err.printf("LocalJDBC Unable to find date for:'%s' from'%s' Time" + startDate.toDate() + "\n", "Cosing Price", tableName); ex.printStackTrace(); SQLException xp = null; while ((xp = ex.getNextException()) != null) { xp.printStackTrace(); } } finally { try { if (results != null) results.close(); if (pstm != null) pstm.close(); if (connection != null) connection.close(); // System.out.printf("Max connect:%d in use:%d\n",mainPool.getMaxConnections(), mainPool.getActiveConnections()); // mainPool.dispose(); } catch (SQLException ex) { Logger.getLogger(LocalJDBC.class.getName()).log(Level.SEVERE, null, ex); } } return ArrayUtils.toPrimitive(closingPrices.toArray(new Double[0])); }
From source file:org.jtotus.database.LocalJDBC.java
License:Open Source License
public HashMap<String, Double> fetchPeriodAsMap(String tableName, DateTime startDate, DateTime endDate) { HashMap<String, Double> retMap = new HashMap<String, Double>(); BigDecimal retValue = null;/*ww w . jav a2s . c o m*/ PreparedStatement pstm = null; java.sql.Date retDate = null; ResultSet results = null; Connection connection = null; try { String query = "SELECT CLOSE, DATE FROM " + this.normTableName(tableName) + " WHERE DATE>=? AND DATE<=? ORDER BY DATE ASC"; // this.createTable(connection, this.normTableName(tableName)); connection = this.getConnection(); pstm = connection.prepareStatement(query); java.sql.Date startSqlDate = new java.sql.Date(startDate.getMillis()); pstm.setDate(1, startSqlDate); java.sql.Date endSqlDate = new java.sql.Date(endDate.getMillis()); pstm.setDate(2, endSqlDate); System.out.printf("fetchPeriod : %s : %s\n", startSqlDate, endSqlDate); DateIterator iter = new DateIterator(startDate, endDate); results = pstm.executeQuery(); DateTime dateCheck; while (results.next()) { retValue = results.getBigDecimal(1); retDate = results.getDate(2); if (retValue == null || retDate == null) { System.err.println("Database is corrupted!"); System.exit(-1); } if (iter.hasNext()) { dateCheck = iter.nextInCalendar(); DateTime compCal = new DateTime(retDate.getTime()); if (debug) { if (retValue != null) { System.out.printf("Fetched:\'%s\' from \'%s\' : value:%f date:%s\n", "Closing Price", tableName, retValue.doubleValue(), retDate.toString()); } else { System.out.printf("Fetched:\'%s\' from \'%s\' : value:%s date:%s\n", "Closing Price", tableName, "is null", retDate.toString()); } } if (compCal.getDayOfMonth() == dateCheck.getDayOfMonth() && compCal.getMonthOfYear() == dateCheck.getMonthOfYear() && compCal.getYear() == dateCheck.getYear()) { retMap.put(formatter.print(compCal), retValue.doubleValue()); continue; } while (((compCal.getDayOfMonth() != dateCheck.getDayOfMonth()) || (compCal.getMonthOfYear() != dateCheck.getMonthOfYear()) || (compCal.getYear() != dateCheck.getYear())) && dateCheck.isBefore(compCal)) { if (fetcher != null) { BigDecimal failOverValue = getFetcher().fetchData(tableName, dateCheck, "CLOSE"); if (failOverValue != null) { retMap.put(formatter.print(dateCheck), retValue.doubleValue()); } if (iter.hasNext()) { System.err.printf("Warning : Miss matching dates for: %s - %s\n", retDate.toString(), dateCheck.toString()); dateCheck = iter.nextInCalendar(); continue; } } else { System.err.printf("Fatal missing fetcher : Miss matching dates: %s - %s\n", retDate.toString(), dateCheck.toString()); return null; } } } } while (iter.hasNext()) { retValue = getFetcher().fetchData(tableName, iter.nextInCalendar(), "CLOSE"); if (retValue != null) { retMap.put(formatter.print(iter.getCurrentAsCalendar()), retValue.doubleValue()); } } } catch (SQLException ex) { System.err.printf("LocalJDBC Unable to find date for:'%s' from'%s' Time" + startDate.toDate() + "\n", "Cosing Price", tableName); // ex.printStackTrace(); // SQLException xp = null; // while((xp = ex.getNextException()) != null) { // xp.printStackTrace(); // } } finally { try { if (results != null) results.close(); if (pstm != null) pstm.close(); if (connection != null) connection.close(); // System.out.printf("Max connect:%d in use:%d\n",mainPool.getMaxConnections(), mainPool.getActiveConnections()); // mainPool.dispose(); } catch (SQLException ex) { Logger.getLogger(LocalJDBC.class.getName()).log(Level.SEVERE, null, ex); } } return retMap; }
From source file:org.kitesdk.apps.examples.report.ScheduledReportJob.java
License:Apache License
public void run() { // TODO: Switch to parameterized views. View<ExampleEvent> view = Datasets.load(ScheduledReportApp.EXAMPLE_DS_URI, ExampleEvent.class); RefinableView<GenericRecord> target = Datasets.load(ScheduledReportApp.REPORT_DS_URI, GenericRecord.class); // Get the view into which this report will be written. DateTime dateTime = getNominalTime().toDateTime(DateTimeZone.UTC); View<GenericRecord> output = target.with("year", dateTime.getYear()) .with("month", dateTime.getMonthOfYear()).with("day", dateTime.getDayOfMonth()) .with("hour", dateTime.getHourOfDay()).with("minute", dateTime.getMinuteOfHour()); Pipeline pipeline = getPipeline();/* w w w. j a v a 2 s. com*/ PCollection<ExampleEvent> events = pipeline.read(CrunchDatasets.asSource(view)); PTable<Long, ExampleEvent> eventsByUser = events.by(new GetEventId(), Avros.longs()); // Count of events by user ID. PTable<Long, Long> userEventCounts = eventsByUser.keys().count(); PCollection<GenericData.Record> report = userEventCounts.parallelDo(new ToUserReport(), Avros.generics(SCHEMA)); pipeline.write(report, CrunchDatasets.asTarget(output)); pipeline.run(); }
From source file:org.kuali.kpme.core.calendar.entry.service.CalendarEntryServiceImpl.java
License:Educational Community License
private DateTime plusSemiMonth(DateTime date) { //so assuming the common pairs of this are the 1st & 16th, and then 15th and the last day, // and 14th with the last day minus 1 //so we'll peek at the current date and try to figure out the best guesses for addition. if (date.getDayOfMonth() == date.dayOfMonth().getMaximumValue()) { //date is on the last day of the month. Set next date to the 15th return date.plusMonths(1).withDayOfMonth(15); } else if (date.getDayOfMonth() == 15) { //we are on the 15th of the month, so now lets go to the end of the month return date.withDayOfMonth(date.dayOfMonth().getMaximumValue()); } else if (date.getDayOfMonth() == 1) { //first of the month, next would be 16 return date.withDayOfMonth(16); } else if (date.getDayOfMonth() == 16) { //16th, so add a month and set day to '1' return date.plusMonths(1).withDayOfMonth(1); } else if (date.getDayOfMonth() == 14) { //14th day, set next one to last day minus 1 return date.withDayOfMonth(date.dayOfMonth().getMaximumValue() - 1); } else if (date.getDayOfMonth() == date.dayOfMonth().getMaximumValue() - 1) { //date is on the second to last day of the month. Set next date to the 14th return date.plusMonths(1).withDayOfMonth(14); } else {/*from ww w . ja va 2s . c o m*/ // so it isn't one of the common dates... i guess we'll just add 15 days... return date.plusDays(15); } }