List of usage examples for org.joda.time DateTime getDayOfMonth
public int getDayOfMonth()
From source file:io.spikex.core.util.CronEntry.java
License:Apache License
public boolean isDefined(final DateTime tm) { boolean defined = false; int month = tm.getMonthOfYear(); int day = tm.getDayOfMonth(); int dow = tm.getDayOfWeek(); int hour = tm.getHourOfDay(); int minute = tm.getMinuteOfHour(); boolean dayDowMatch = true; if (!isEveryDay()) { dayDowMatch = isDayDefined(day); }/* ww w .j a v a 2 s .c o m*/ if (!isEveryDow()) { dayDowMatch = isDowDefined(dow); } if (!isEveryDay() && !isEveryDow()) { dayDowMatch = (isDayDefined(day) || isDowDefined(dow)); } if (isMonthDefined(month) && dayDowMatch && isHourDefined(hour) && isMinuteDefined(minute)) { defined = true; } // System.out.println("Defined " + defined + " - month: " + month + " day: " + day + " dow: " + dow // +" hour: " + hour + " minute: " + minute + " dayOrDowMatch: " + dayDowMatch); // System.out.println("dayDowMatch: " + dayDowMatch + " isMonthDefined: " + isMonthDefined(month) // + " isHourDefined: " + isHourDefined(hour) + " isMinuteDefined: " + isMinuteDefined(minute)); return defined; }
From source file:io.warp10.script.functions.TSELEMENTS.java
License:Apache License
@Override public Object apply(WarpScriptStack stack) throws WarpScriptException { Object obj = stack.peek();//w ww .ja va 2 s .c o m String tz = null; if (obj instanceof String) { tz = (String) obj; stack.pop(); } else if (!(obj instanceof Long)) { throw new WarpScriptException(getName() + " operates on a timestamp or a timestamp + timezone."); } DateTimeZone dtz = this.tzones.get(tz); if (null == dtz) { dtz = DateTimeZone.forID(null == tz ? "UTC" : tz); this.tzones.put(tz, dtz); } obj = stack.pop(); if (!(obj instanceof Long)) { throw new WarpScriptException(getName() + " operates on a timestamp or a timestamp + timezone."); } long ts = (long) obj; // Convert ts to milliseconds long tsms = ts / Constants.TIME_UNITS_PER_MS; DateTime dt = new DateTime(tsms, dtz); // Extract components into an array List<Long> elements = new ArrayList<Long>(); elements.add((long) dt.getYear()); elements.add((long) dt.getMonthOfYear()); elements.add((long) dt.getDayOfMonth()); elements.add((long) dt.getHourOfDay()); elements.add((long) dt.getMinuteOfHour()); elements.add((long) dt.getSecondOfMinute()); elements.add(ts % Constants.TIME_UNITS_PER_S); elements.add((long) dt.getDayOfYear()); elements.add((long) dt.getDayOfWeek()); elements.add((long) dt.getWeekOfWeekyear()); stack.push(elements); return stack; }
From source file:io.warp10.script.mapper.MapperDayOfMonth.java
License:Apache License
@Override public Object apply(Object[] args) throws WarpScriptException { long tick = (long) args[0]; long[] locations = (long[]) args[4]; long[] elevations = (long[]) args[5]; long location = locations[0]; long elevation = elevations[0]; DateTime dt = new DateTime(tick / Constants.TIME_UNITS_PER_MS, this.dtz); return new Object[] { tick, location, elevation, dt.getDayOfMonth() }; }
From source file:isjexecact.br.com.inso.utils.Funcoes.java
/** * Retorna o dia de uma data./* w w w . ja v a 2 s . co m*/ * @param data Data a ser processada. * @return Dia da data. */ public static int getDay(Date data) { if (data == null) { return 0; } // Glauber 11/09/2014 - Estou trocando pelo componente joda-time para me livrar da dor de cabea de utiilzar as classes nativa do Java. DateTime dateTime = new DateTime(data); return dateTime.getDayOfMonth(); // Calendar calendario = new GregorianCalendar(); // calendario.setTime(data); // return calendario.get(Calendar.DAY_OF_MONTH) ; }
From source file:it.fabaris.wfp.widget.DateTimeWidget.java
License:Open Source License
/** * set the answer to the answer Widget//from w w w . j ava 2 s .c o m * getting in it from the FormEntryPrompt * otherwise create time widget with * the current time */ private void setAnswer() { if (mPrompt.getAnswerValue() != null) { DateTime ldt = new DateTime(((Date) ((DateTimeData) mPrompt.getAnswerValue()).getValue()).getTime()); //mDatePicker.init(ldt.getYear(), ldt.getMonthOfYear() - 1, ldt.getDayOfMonth(), mDateListener); //LA DATA DI SINCRONIZZAZIONE ERA SETTATA CON UN MESE INDIETRO mDatePicker.init(ldt.getYear(), ldt.getMonthOfYear(), ldt.getDayOfMonth(), mDateListener); mTimePicker.setCurrentHour(ldt.getHourOfDay()); mTimePicker.setCurrentMinute(ldt.getMinuteOfHour()); } else { // create time widget with current time as of right now clearAnswer(); } }
From source file:it.fabaris.wfp.widget.DateWidget.java
License:Open Source License
/** * if there is an answer in the FormEntryPrompt * put it in the answer Widget, clean//from ww w .j a v a 2 s . co m * the widget value otherwise */ private void setAnswer() { if (mPrompt.getAnswerValue() != null) { DateTime ldt = new DateTime(((Date) ((DateData) mPrompt.getAnswerValue()).getValue()).getTime()); mDatePicker.init(ldt.getYear(), ldt.getMonthOfYear() - 1, ldt.getDayOfMonth(), mDateListener); //mDatePicker.init(ldt.getYear(), ldt.getMonthOfYear() - 1, ldt.getDayOfMonth(), mDateListener); } else { // create date widget with current time as of right now clearAnswer(); } }
From source file:it.fabaris.wfp.widget.DateWidget.java
License:Open Source License
/** * Resets date to today.// ww w . ja v a 2 s .c om */ @Override public void clearAnswer() { DateTime ldt = new DateTime(); mDatePicker.init(ldt.getYear(), ldt.getMonthOfYear() - 1, ldt.getDayOfMonth(), mDateListener); //mDatePicker.init(ldt.getYear(), ldt.getMonthOfYear() - 1, ldt.getDayOfMonth(), mDateListener); }
From source file:it.mazzoni.twilight.Twilight.java
License:Open Source License
private boolean updateData() { DateTime dt = new DateTime(); int dst = dt.getZone().isStandardOffset(dt.getMillis()) ? 0 : 1; int offset = dt.getZone().getStandardOffset(dt.getMillis()) / 3600000; //LOG.log(Level.INFO, "Current TIME: {0}/{1} {2} DST: {3}", new Object[]{dt.getDayOfMonth(), dt.getMonthOfYear(), offset, dst}); Document doc = getXMLStatusFile(dt.getDayOfMonth(), dt.getMonthOfYear(), offset, dst); //parse xml //from w w w. j a va 2 s .co m if (doc != null) { Node sunriseNode = doc.getElementsByTagName("sunrise").item(0); Node sunsetNode = doc.getElementsByTagName("sunset").item(0); // compara con l'ora attuale String srTime[] = sunriseNode.getFirstChild().getNodeValue().split(":"); String ssTime[] = sunsetNode.getFirstChild().getNodeValue().split(":"); TLU.setSunriseTime(new DateTime(dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth(), Integer.parseInt(srTime[0]), Integer.parseInt(srTime[1]), Integer.parseInt(srTime[2]))); TLU.setSunsetTime(new DateTime(dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth(), Integer.parseInt(ssTime[0]), Integer.parseInt(ssTime[1]), Integer.parseInt(ssTime[2]))); LOG.log(Level.INFO, "Sunrise at: {0} Sunset at:{1}", new Object[] { TLU.getSunriseTime(), TLU.getSunsetTime() }); return true; } else { return false; } }
From source file:javaapplication1.GenerateTest2DK.java
public static void main(String[] args) throws IOException { int episodeNumber = 0; BufferedReader buffreader = null; try {/* w ww. ja v a2 s. co m*/ // open the file for reading InputStream fis = new FileInputStream("kuasha-episode.txt"); // if file the available for reading if (fis != null) { // prepare the file for reading InputStreamReader chapterReader = new InputStreamReader(fis); buffreader = new BufferedReader(chapterReader); String line = null; while (true) { try { line = buffreader.readLine(); } catch (Exception e) { } if (line == null) break; songPath.add(line); episodeNumber++; } /*String line; // read every line of the file into the line-variable, on line at the time do { line = buffreader.readLine(); // do something with the line System.out.println(line); } while (line != null); */ } } catch (Exception e) { } finally { } String[] monthStr2 = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nove", "Dec" }; String[] monthStr = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; String[] urlImage = { "http://i.imgur.com/Pks8tmU.jpg", "http://i.imgur.com/UHv8tdw.jpg", "http://i.imgur.com/AybMRiN.jpg", "http://i.imgur.com/J7gMxN4.jpg", "http://i.imgur.com/8C3N9lN.jpg", "http://i.imgur.com/p5RjLUq.jpg", "http://i.imgur.com/vp97ZQe.jpg" }; List<DateTime> fridays = new ArrayList<>(); boolean reachedAFriday = false; String start = "12/08/2010"; String end = "01/02/2011"; DateTimeFormatter pattern = DateTimeFormat.forPattern("dd/mm/yyyy"); DateTime startDate = new DateTime();//(2018, 06, 22, 0, 0, 0, 0);//pattern.parseDateTime(start); // year-month-day DateTime endDate = new DateTime(2010, 1, 1, 0, 0, 0, 0);//pattern.parseDateTime(end); int startRange = 0; int yearID = 0; int albumID = 0; int songID = 0; String url = "{\"albumList\":["; String prevYear = ""; Random r = new Random(); int i1 = (r.nextInt(80) + 65); while (startDate.isAfter(endDate)) { if (songID >= episodeNumber) break; String dayOfYaer = "" + startDate.getYear(); if (!prevYear.equals(dayOfYaer)) { url += "{\"yearID\":\"" + yearID + "\", \"yearName\":\"" + "YEAR-" + dayOfYaer + "\", \"monthList\":["; prevYear = "" + startDate.getYear(); yearID++; } String dayOfMonth = "" + monthStr[startDate.getMonthOfYear() - 1]; url += "{\"albumID\":\"" + albumID + "\", \"albumName\":\"" + "" + dayOfMonth + "\", \"songList\":["; //+"Month-"+startDate.dayOfMonth() +"\"},"; //System.out.println("fahad -- "+ (startDate.getDayOfMonth()-1)); if (startRange == 0) startRange = songID; while ((monthStr[startDate.getMonthOfYear() - 1]).equals(dayOfMonth)) { if (songID >= episodeNumber) break; if (startDate.getDayOfWeek() == DateTimeConstants.MONDAY) { fridays.add(startDate); reachedAFriday = true; String MothWithTwoDigit = String.format("%02d", startDate.getMonthOfYear()); String dateWithTwoDigit = String.format("%02d", startDate.getDayOfMonth()); String date = startDate.getYear() + "-" + MothWithTwoDigit + "-" + dateWithTwoDigit; String EpisodesName = "Ep-" + dateWithTwoDigit + " " + monthStr2[startDate.getMonthOfYear() - 1] + "," + startDate.getYear(); if (songID == 0) EpisodesName = "(New)" + EpisodesName; path = songPath.get(episodeNumber - songID - 1);//"http://dl.bhoot-fm.com/Bhoot-FM_"+date+"_(Bhoot-FM.com).mp3"; artist = "Kuasha"; composer = "ABC-Radio"; imageUrl = urlImage[r.nextInt(7)];//"http://3.bp.blogspot.com/-nd09lbpK1Mk/U7hkntBHF4I/AAAAAAAAAM8/FFsAfjT9tW8/s1600/bhoot.jpg"; url += "{\"songID\":\"" + songID + "\", \"title\":\"" + EpisodesName + "\", \"artist\":\"" + artist + "\", \"path\":\"" + path + "\", \"albumId\":\"" + albumID + "\", \"composer\":\"" + composer + "\", \"imageUrl\":\"" + imageUrl + "\"},"; songID++; } if (reachedAFriday) { startDate = startDate.minusWeeks(1); } else { startDate = startDate.minusDays(1); } System.out.println("fahad -- " + (startDate.getDayOfMonth() - 1)); } albumID++; url = url.substring(0, url.length() - 1) + "], \"songListRange\":\"" + startRange + "-" + (songID - 1) + "\"},"; startRange = 0; if (!prevYear.equals("" + startDate.getYear())) { url = url.substring(0, url.length() - 1) + "]},"; //prevYear = dayOfYaer; } } url = url.substring(0, url.length() - 1) + "]}]}";//]} System.out.println(url); File file = new File("filename_kuasha.txt"); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(url); bw.close(); System.out.println("Done"); }
From source file:javaapplication1.GenerateTest2Dor.java
public static void main(String[] args) throws IOException { BufferedReader buffreader = null; try {//from w ww . ja v a 2s . c o m // open the file for reading InputStream fis = new FileInputStream("Dor.txt"); // if file the available for reading if (fis != null) { // prepare the file for reading InputStreamReader chapterReader = new InputStreamReader(fis); buffreader = new BufferedReader(chapterReader); String line = null; while (true) { try { line = buffreader.readLine(); } catch (Exception e) { } if (line == null) break; songPath.add(line); } /*String line; // read every line of the file into the line-variable, on line at the time do { line = buffreader.readLine(); // do something with the line System.out.println(line); } while (line != null); */ } } catch (Exception e) { } finally { } String[] monthStr2 = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nove", "Dec" }; String[] monthStr = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; String[] urlImage = { "http://i.imgur.com/DMmPf5f.jpg", "http://i.imgur.com/8C3N9lN.jpg", "http://i.imgur.com/MGQSXb1.jpg", "http://i.imgur.com/nyv8gOD.jpg", "http://i.imgur.com/kzr9p5M.jpg", "http://i.imgur.com/nBTPbty.jpg", "http://i.imgur.com/VvLI4sY.jpg" }; List<DateTime> fridays = new ArrayList<>(); boolean reachedAFriday = false; String start = "12/08/2010"; String end = "01/02/2011"; DateTimeFormatter pattern = DateTimeFormat.forPattern("dd/mm/yyyy"); DateTime startDate = new DateTime(2018, 03, 03, 0, 0, 0, 0);//pattern.parseDateTime(start); // year-month-day DateTime endDate = new DateTime(2010, 1, 1, 0, 0, 0, 0);//pattern.parseDateTime(end); int startRange = 0; int yearID = 0; int albumID = 0; int songID = 0; int episodeNumber = 172; String url = "{\"albumList\":["; String prevYear = ""; Random r = new Random(); int i1 = (r.nextInt(80) + 65); while (startDate.isAfter(endDate)) { if (songID >= episodeNumber) break; String dayOfYaer = "" + startDate.getYear(); if (!prevYear.equals(dayOfYaer)) { url += "{\"yearID\":\"" + yearID + "\", \"yearName\":\"" + "YEAR-" + dayOfYaer + "\", \"monthList\":["; prevYear = "" + startDate.getYear(); yearID++; } String dayOfMonth = "" + monthStr[startDate.getMonthOfYear() - 1]; url += "{\"albumID\":\"" + albumID + "\", \"albumName\":\"" + "" + dayOfMonth + "\", \"songList\":["; //+"Month-"+startDate.dayOfMonth() +"\"},"; //System.out.println("fahad -- "+ (startDate.getDayOfMonth()-1)); if (startRange == 0) startRange = songID; while ((monthStr[startDate.getMonthOfYear() - 1]).equals(dayOfMonth)) { if (songID >= episodeNumber) break; if (startDate.getDayOfWeek() == DateTimeConstants.THURSDAY) { fridays.add(startDate); reachedAFriday = true; String MothWithTwoDigit = String.format("%02d", startDate.getMonthOfYear()); String dateWithTwoDigit = String.format("%02d", startDate.getDayOfMonth()); String date = startDate.getYear() + "-" + MothWithTwoDigit + "-" + dateWithTwoDigit; String EpisodesName = "Ep-" + dateWithTwoDigit + " " + monthStr2[startDate.getMonthOfYear() - 1] + "," + startDate.getYear(); if (songID == 0) EpisodesName = "(New)" + EpisodesName; path = songPath.get(episodeNumber - songID - 1);//"http://dl.bhoot-fm.com/Bhoot-FM_"+date+"_(Bhoot-FM.com).mp3"; artist = "Dor"; composer = "ABC-Radio"; imageUrl = urlImage[r.nextInt(7)];//"http://3.bp.blogspot.com/-nd09lbpK1Mk/U7hkntBHF4I/AAAAAAAAAM8/FFsAfjT9tW8/s1600/bhoot.jpg"; url += "{\"songID\":\"" + songID + "\", \"title\":\"" + EpisodesName + "\", \"artist\":\"" + artist + "\", \"path\":\"" + path + "\", \"albumId\":\"" + albumID + "\", \"composer\":\"" + composer + "\", \"imageUrl\":\"" + imageUrl + "\"},"; songID++; } if (reachedAFriday) { startDate = startDate.minusWeeks(1); } else { startDate = startDate.minusDays(1); } System.out.println("fahad -- " + (startDate.getDayOfMonth() - 1)); } albumID++; url = url.substring(0, url.length() - 1) + "], \"songListRange\":\"" + startRange + "-" + (songID - 1) + "\"},"; startRange = 0; if (!prevYear.equals("" + startDate.getYear())) { url = url.substring(0, url.length() - 1) + "]},"; //prevYear = dayOfYaer; } } url = url.substring(0, url.length() - 1) + "]}]}";//]} System.out.println(url); File file = new File("filename_dor.txt"); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(url); bw.close(); System.out.println("Done"); }