List of usage examples for org.joda.time DateTime getYear
public int getYear()
From source file:com.chiorichan.dvr.storage.Interface.java
License:Mozilla Public License
public File calculateContainingFile(DateTime td, String inputName) { String sep = System.getProperty("file.separator", "/"); // Main storage folder File file = new File(DVRLoader.getConfiguration().getString("config.storage", DVRLoader.instance.getDataFolder().getAbsolutePath())); // [storage]/2014/126/video1/block_[specialepoch].opv file = new File(file, td.getYear() + sep + td.getDayOfYear() + sep + inputName); // Create the needed directory structure. file.mkdirs();/*from ww w .jav a 2 s . c o m*/ return new File(file, "block_" + getTen(td) + ".opv"); }
From source file:com.clevercloud.bianca.lib.date.DateModule.java
License:Open Source License
/** * Returns the parsed date.//from w ww .j a v a2 s .co m */ public Value strptime(Env env, String date, String format) { ArrayValueImpl array = new ArrayValueImpl(); DateTimeFormatterBuilder fb = new DateTimeFormatterBuilder(); int length = format.length(); for (int i = 0; i < length; i++) { char ch = format.charAt(i); if (ch != '%') { fb.appendLiteral(ch); continue; } switch (format.charAt(++i)) { case 'a': fb.appendDayOfWeekShortText(); break; case 'A': fb.appendDayOfWeekText(); break; case 'h': case 'b': fb.appendMonthOfYearShortText(); ; break; case 'B': fb.appendMonthOfYearText(); break; // TODO: case 'c' case 'C': fb.appendCenturyOfEra(2, 2); break; case 'd': fb.appendDayOfMonth(2); break; case 'D': fb.appendMonthOfYear(2); fb.appendLiteral('/'); fb.appendDayOfMonth(2); fb.appendLiteral('/'); fb.appendYear(2, 2); break; // TODO: case 'e' case 'F': fb.appendYear(4, 4); fb.appendLiteral('-'); fb.appendMonthOfYear(2); fb.appendLiteral('-'); fb.appendDayOfMonth(2); break; // TODO: case 'g' // TODO: case 'G' case 'H': fb.appendHourOfDay(2); break; case 'I': fb.appendHourOfHalfday(2); break; case 'j': fb.appendDayOfYear(3); break; // TODO: case 'l' case 'm': fb.appendMonthOfYear(2); break; case 'M': fb.appendMinuteOfHour(2); break; case 'n': fb.appendLiteral("\n"); break; case 'p': case 'P': fb.appendHalfdayOfDayText(); break; case 'r': fb.appendHourOfHalfday(2); fb.appendLiteral(':'); fb.appendMinuteOfHour(2); fb.appendLiteral(':'); fb.appendSecondOfMinute(2); fb.appendLiteral(' '); fb.appendHalfdayOfDayText(); break; case 'R': fb.appendHourOfDay(2); fb.appendLiteral(':'); fb.appendMinuteOfHour(2); break; // TODO: case 's' case 'S': fb.appendSecondOfMinute(2); break; case 't': fb.appendLiteral("\t"); break; case 'T': fb.appendHourOfDay(2); fb.appendLiteral(':'); fb.appendMinuteOfHour(2); fb.appendLiteral(':'); fb.appendSecondOfMinute(2); break; // TODO: case 'u' // TODO: case 'U' // TODO: case 'V' // TODO: case 'w' // TODO: case 'W' // TODO: case 'x' // TODO: case 'X' case 'y': fb.appendYear(2, 2); break; case 'Y': fb.appendYear(4, 4); break; case 'z': fb.appendTimeZoneOffset(null, true, 2, 2); break; case 'Z': fb.appendTimeZoneName(); break; case '%': fb.appendLiteral('%'); break; default: fb.appendLiteral(ch); } } DateTimeFormatter dtf = fb.toFormatter().withLocale(Locale.getDefault()).withOffsetParsed(); org.joda.time.DateTime dt = new org.joda.time.DateTime(); String unparsed = ""; try { dt = dtf.parseDateTime(date); } catch (IllegalArgumentException e) { String delims = "[\"]+"; String[] splits = e.getMessage().split(delims); unparsed = unparsed.concat(splits[3]); } // According to manual strptime(3) if (dt.getCenturyOfEra() == 0) { if (dt.getYear() > 68) { dt = dt.withCenturyOfEra(19); } else { dt = dt.withCenturyOfEra(20); } } array.put("tm_sec", dt.getSecondOfMinute()); array.put("tm_min", dt.getMinuteOfHour()); array.put("tm_hour", dt.getHourOfDay()); array.put("tm_mday", dt.getDayOfMonth()); array.put("tm_mon", dt.getMonthOfYear() - 1); array.put("tm_year", dt.getYearOfCentury() + ((dt.getCenturyOfEra() - 19) * 100)); // Years since 1900 array.put("tm_wday", dt.getDayOfWeek() % 7); array.put("tm_yday", dt.getDayOfYear() - 1); array.put("unparsed", unparsed); return array; }
From source file:com.cloudhopper.commons.util.DateTimeUtil.java
License:Apache License
/** * Null-safe method that returns a new instance of a DateTime object rounded * downwards to the nearest year. Note that the nearest valid year is actually * the first of that given year (Jan 1). The time zone of the returned DateTime * instance will be the same as the argument. Similar to a floor() function * on a float.<br>/*from w ww .j a va2 s . c o m*/ * Examples: * <ul> * <li>null -> null * <li>"2009-06-24 13:24:51.476 -8:00" -> "2009-01-01 00:00:00.000 -8:00" * </ul> * @param value The DateTime value to round downward * @return Null if the argument is null or a new instance of the DateTime * value rounded downwards to the nearest year. */ public static DateTime floorToYear(DateTime value) { if (value == null) { return null; } return new DateTime(value.getYear(), 1, 1, 0, 0, 0, 0, value.getZone()); }
From source file:com.cloudhopper.commons.util.DateTimeUtil.java
License:Apache License
/** * Null-safe method that returns a new instance of a DateTime object rounded * downwards to the nearest month. Note that the nearest valid month is actually * the first of that given month (1st day of month). The time zone of the returned DateTime * instance will be the same as the argument. Similar to a floor() function * on a float.<br>//from w w w.jav a 2 s . c o m * Examples: * <ul> * <li>null -> null * <li>"2009-06-24 13:24:51.476 -8:00" -> "2009-06-01 00:00:00.000 -8:00" * </ul> * @param value The DateTime value to round downward * @return Null if the argument is null or a new instance of the DateTime * value rounded downwards to the nearest month. */ public static DateTime floorToMonth(DateTime value) { if (value == null) { return null; } return new DateTime(value.getYear(), value.getMonthOfYear(), 1, 0, 0, 0, 0, value.getZone()); }
From source file:com.cloudhopper.commons.util.DateTimeUtil.java
License:Apache License
/** * Null-safe method that returns a new instance of a DateTime object rounded * downwards to the nearest day. The time zone of the returned DateTime * instance will be the same as the argument. Similar to a floor() function * on a float.<br>/*from w w w . j ava 2 s . com*/ * Examples: * <ul> * <li>null -> null * <li>"2009-06-24 13:24:51.476 -8:00" -> "2009-06-24 00:00:00.000 -8:00" * </ul> * @param value The DateTime value to round downward * @return Null if the argument is null or a new instance of the DateTime * value rounded downwards to the nearest day. */ public static DateTime floorToDay(DateTime value) { if (value == null) { return null; } return new DateTime(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth(), 0, 0, 0, 0, value.getZone()); }
From source file:com.cloudhopper.commons.util.DateTimeUtil.java
License:Apache License
/** * Null-safe method that returns a new instance of a DateTime object rounded * downwards to the nearest hour. The time zone of the returned DateTime * instance will be the same as the argument. Similar to a floor() function * on a float.<br>//from w w w.j a v a 2 s. c o m * Examples: * <ul> * <li>null -> null * <li>"2009-06-24 13:24:51.476 -8:00" -> "2009-06-24 13:00:00.000 -8:00" * </ul> * @param value The DateTime value to round downward * @return Null if the argument is null or a new instance of the DateTime * value rounded downwards to the nearest hour. */ public static DateTime floorToHour(DateTime value) { if (value == null) { return null; } return new DateTime(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth(), value.getHourOfDay(), 0, 0, 0, value.getZone()); }
From source file:com.cloudhopper.commons.util.DateTimeUtil.java
License:Apache License
/** * Null-safe method that returns a new instance of a DateTime object rounded * downwards to the nearest specified period in minutes. For example, if * a period of 5 minutes is requested, a time of "2009-06-24 13:24:51.476 -8:00" * would return a datetime of "2009-06-24 13:20:00.000 -8:00". The time zone of the * returned DateTime instance will be the same as the argument. Similar to a * floor() function on a float.<br> * NOTE: While any period in minutes between 1 and 59 can be passed into this * method, its only useful if the value can be evenly divided into 60 to make * it as useful as possible.<br>//from w w w. j av a 2s . co m * Examples: * <ul> * <li>null -> null * <li>5: "2009-06-24 13:39:51.476 -8:00" -> "2009-06-24 13:35:00.000 -8:00" * <li>10: "2009-06-24 13:39:51.476 -8:00" -> "2009-06-24 13:30:00.000 -8:00" * <li>15: "2009-06-24 13:39:51.476 -8:00" -> "2009-06-24 13:30:00.000 -8:00" * <li>20: "2009-06-24 13:39:51.476 UTC" -> "2009-06-24 13:20:00.000 UTC" * </ul> * @param value The DateTime value to round downward * @return Null if the argument is null or a new instance of the DateTime * value rounded downwards to the nearest period in minutes. */ public static DateTime floorToMinutePeriod(DateTime value, int periodInMinutes) { if (value == null) { return null; } if (periodInMinutes <= 0 || periodInMinutes > 59) { throw new IllegalArgumentException("period in minutes must be > 0 and <= 59"); } int min = value.getMinuteOfHour(); min = (min / periodInMinutes) * periodInMinutes; return new DateTime(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth(), value.getHourOfDay(), min, 0, 0, value.getZone()); }
From source file:com.cloudhopper.commons.util.DateTimeUtil.java
License:Apache License
/** * Null-safe method that returns a new instance of a DateTime object rounded * downwards to the nearest minute. The time zone of the returned DateTime * instance will be the same as the argument. Similar to a floor() function * on a float.<br>//w ww .j av a2 s .co m * Examples: * <ul> * <li>null -> null * <li>"2009-06-24 13:24:51.476 -8:00" -> "2009-06-24 13:24:00.000 -8:00" * </ul> * @param value The DateTime value to round downward * @return Null if the argument is null or a new instance of the DateTime * value rounded downwards to the nearest minute. */ public static DateTime floorToMinute(DateTime value) { if (value == null) { return null; } return new DateTime(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth(), value.getHourOfDay(), value.getMinuteOfHour(), 0, 0, value.getZone()); }
From source file:com.cloudhopper.commons.util.DateTimeUtil.java
License:Apache License
/** * Null-safe method that returns a new instance of a DateTime object rounded * downwards to the nearest second. The time zone of the returned DateTime * instance will be the same as the argument. Similar to a floor() function * on a float.<br>//from www.ja va 2s .co m * Examples: * <ul> * <li>null -> null * <li>"2009-06-24 13:24:51.476 -8:00" -> "2009-06-24 13:24:51.000 -8:00" * </ul> * @param value The DateTime value to round downward * @return Null if the argument is null or a new instance of the DateTime * value rounded downwards to the nearest second. */ public static DateTime floorToSecond(DateTime value) { if (value == null) { return null; } return new DateTime(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth(), value.getHourOfDay(), value.getMinuteOfHour(), value.getSecondOfMinute(), 0, value.getZone()); }
From source file:com.cloudhopper.commons.util.time.DateTimePeriod.java
License:Apache License
/** * Create a list of DateTimePeriods that represent the last year of * YearMonth periods. For example, if its currently January 2009, this * would return periods representing "January 2009, December 2008, ... February 2008" * @param zone/*from w w w . ja va 2 s . c om*/ * @return */ static public List<DateTimePeriod> createLastYearMonths(DateTimeZone zone) { ArrayList<DateTimePeriod> periods = new ArrayList<DateTimePeriod>(); // get today's date DateTime now = new DateTime(zone); // start with today's current month and 11 others (last 12 months) for (int i = 0; i < 12; i++) { // create a new period DateTimePeriod period = createMonth(now.getYear(), now.getMonthOfYear(), zone); periods.add(period); // subtract 1 month now = now.minusMonths(1); } return periods; }