List of usage examples for org.joda.time DateTimeZone getDefault
public static DateTimeZone getDefault()
From source file:AgeCalculator.java
License:Apache License
private void addTopArea(Container container) { JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.add(fixedHeight(new JLabel("Birthdate"))); panel.add(Box.createHorizontalStrut(10)); final JTextField birthdateField = new JTextField(iBirthdateStr + ' '); Document doc = birthdateField.getDocument(); doc.addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent e) { update(e);/*from ww w . jav a 2s.c o m*/ } public void removeUpdate(DocumentEvent e) { update(e); } public void changedUpdate(DocumentEvent e) { update(e); } private void update(DocumentEvent e) { iBirthdateStr = birthdateField.getText(); updateResults(); } }); panel.add(fixedHeight(birthdateField)); panel.add(Box.createHorizontalStrut(10)); Object[] ids = DateTimeZone.getAvailableIDs().toArray(); final JComboBox zoneSelector = new JComboBox(ids); zoneSelector.setSelectedItem(DateTimeZone.getDefault().getID()); panel.add(fixedSize(zoneSelector)); zoneSelector.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String id = (String) zoneSelector.getSelectedItem(); iChronology = ISOChronology.getInstance(DateTimeZone.forID(id)); updateResults(); } }); container.add(fixedHeight(panel)); }
From source file:achmad.rifai.admin.Coba.java
public static void main(String[] args) { org.joda.time.DateTime a = org.joda.time.DateTime.now(); System.out.println("" + a); java.util.Date b = a.toDate(); System.out.println("" + b); org.joda.time.DateTime c = new org.joda.time.DateTime(b.getTime(), DateTimeZone.getDefault()); System.out.println("" + c); }
From source file:achmad.rifai.admin.ui.terima.Add.java
private void saving() { if (t == null) { t = new achmad.rifai.erp1.entity.Terima(); t.setDeleted(false);//from w ww .j ava 2 s. co m } t.setJurnal(jurnal.getItemAt(jurnal.getSelectedIndex())); t.setKode(kode.getText()); java.util.Date d = (java.util.Date) waktu.getValue(); t.setTgl(new org.joda.time.DateTime(d.getTime(), DateTimeZone.getDefault())); t.setUang(org.joda.money.Money.of(CurrencyUnit.of("IDR"), Long.parseLong(uang.getText()))); }
From source file:achmad.rifai.admin.ui.tracks.Loge.java
public achmad.rifai.erp1.entity.Jejak genJejak() { achmad.rifai.erp1.entity.Jejak j = new achmad.rifai.erp1.entity.Jejak(); j.setAksi(aksi.getText());/*from ww w . j a v a 2 s . c o m*/ java.util.Date tgl = (java.util.Date) jam.getValue(); org.joda.time.DateTime d = new org.joda.time.DateTime(tgl.getTime(), DateTimeZone.getDefault()); j.setWaktu(d); return j; }
From source file:app.rappla.calendar.Date.java
License:Open Source License
/** * Constructor/*from ww w . ja v a 2 s .c o m*/ * * @param icalStr * One or more lines of iCalendar that specifies a date * @param parseMode * PARSE_STRICT or PARSE_LOOSE */ public Date(String icalStr) throws ParseException, BogusDataException { super(icalStr); year = month = day = 0; hour = minute = second = 0; for (int i = 0; i < attributeList.size(); i++) { Attribute a = attributeAt(i); String aname = a.name.toUpperCase(Locale.ENGLISH); String aval = a.value.toUpperCase(Locale.ENGLISH); // TODO: not sure if any attributes are allowed here... // Look for VALUE=DATE or VALUE=DATE-TIME // DATE means untimed for the event if (aname.equals("VALUE")) { if (aval.equals("DATE")) { dateOnly = true; } else if (aval.equals("DATE-TIME")) { dateOnly = false; } } else if (aname.equals("TZID")) { tzid = a.value; } else { // TODO: anything else allowed here? } } String inDate = value; if (inDate.length() < 8) { // Invalid format throw new ParseException("Invalid date format '" + inDate + "'", inDate); } // Make sure all parts of the year are numeric. for (int i = 0; i < 8; i++) { char ch = inDate.charAt(i); if (ch < '0' || ch > '9') { throw new ParseException("Invalid date format '" + inDate + "'", inDate); } } year = Integer.parseInt(inDate.substring(0, 4)); month = Integer.parseInt(inDate.substring(4, 6)); day = Integer.parseInt(inDate.substring(6, 8)); if (day < 1 || day > 31 || month < 1 || month > 12) throw new BogusDataException("Invalid date '" + inDate + "'", inDate); // Make sure day of month is valid for specified month if (year % 4 == 0) { // leap year if (day > leapMonthDays[month - 1]) { throw new BogusDataException("Invalid day of month '" + inDate + "'", inDate); } } else { if (day > monthDays[month - 1]) { throw new BogusDataException("Invalid day of month '" + inDate + "'", inDate); } } // TODO: parse time, handle localtime, handle timezone if (inDate.length() > 8) { // TODO make sure dateOnly == false if (inDate.charAt(8) == 'T') { try { hour = Integer.parseInt(inDate.substring(9, 11)); minute = Integer.parseInt(inDate.substring(11, 13)); second = Integer.parseInt(inDate.substring(13, 15)); if (hour > 23 || minute > 59 || second > 59) { throw new BogusDataException("Invalid time in date string '" + inDate + "'", inDate); } if (inDate.length() > 15) { isUTC = inDate.charAt(15) == 'Z'; } } catch (NumberFormatException nef) { throw new BogusDataException("Invalid time in date string '" + inDate + "' - " + nef, inDate); } } else { // Invalid format throw new ParseException("Invalid date format '" + inDate + "'", inDate); } } else { // Just date, no time dateOnly = true; } if (isUTC && !dateOnly) { // Use Joda Time to convert UTC to localtime DateTime utcDateTime = new DateTime(DateTimeZone.UTC); utcDateTime = utcDateTime.withDate(year, month, day).withTime(hour, minute, second, 0); DateTime localDateTime = utcDateTime.withZone(DateTimeZone.getDefault()); year = localDateTime.getYear(); month = localDateTime.getMonthOfYear(); day = localDateTime.getDayOfMonth(); hour = localDateTime.getHourOfDay(); minute = localDateTime.getMinuteOfHour(); second = localDateTime.getSecondOfMinute(); } else if (tzid != null) { DateTimeZone tz = DateTimeZone.forID(tzid); if (tz != null) { // Convert to localtime DateTime utcDateTime = new DateTime(tz); utcDateTime = utcDateTime.withDate(year, month, day).withTime(hour, minute, second, 0); DateTime localDateTime = utcDateTime.withZone(DateTimeZone.getDefault()); year = localDateTime.getYear(); month = localDateTime.getMonthOfYear(); day = localDateTime.getDayOfMonth(); hour = localDateTime.getHourOfDay(); minute = localDateTime.getMinuteOfHour(); second = localDateTime.getSecondOfMinute(); // Since we have converted to localtime, remove the TZID // attribute this.removeNamedAttribute("TZID"); } } isUTC = false; // Add attribute that says date-only or date with time if (dateOnly) addAttribute("VALUE", "DATE"); else addAttribute("VALUE", "DATE-TIME"); }
From source file:arjdbc.util.DateTimeUtils.java
License:Open Source License
public static RubyTime parseDateTime(final ThreadContext context, final String str) throws IllegalArgumentException { boolean hasDate = false; int year = 2000; int month = 1; int day = 1;//ww w. j a v a2 s . c o m boolean hasTime = false; int minute = 0; int hour = 0; int second = 0; int millis = 0; long nanos = 0; DateTimeZone zone = null; boolean bcEra = false; // We try to parse these fields in order; all are optional // (but some combinations don't make sense, e.g. if you have // both date and time then they must be whitespace-separated). // At least one of date and time must be present. // leading whitespace // yyyy-mm-dd // whitespace // hh:mm:ss // whitespace // timezone in one of the formats: +hh, -hh, +hh:mm, -hh:mm // whitespace // if date is present, an era specifier: AD or BC // trailing whitespace final int len = str.length(); int start = nonSpaceIndex(str, 0, len); // Skip leading whitespace int end = nonDigitIndex(str, start, len); // Possibly read date. if (end < len && str.charAt(end) == '-') { hasDate = true; // year year = extractIntValue(str, start, end); start = end + 1; // Skip '-' // month end = nonDigitIndex(str, start, len); month = extractIntValue(str, start, end); char sep = str.charAt(end); if (sep != '-') { throw new IllegalArgumentException("expected date to be dash-separated, got '" + sep + "'"); } start = end + 1; // Skip '-' // day of month end = nonDigitIndex(str, start, len); day = extractIntValue(str, start, end); start = nonSpaceIndex(str, end, len); // Skip trailing whitespace } // Possibly read time. if (start < len && Character.isDigit(str.charAt(start))) { hasTime = true; // hours end = nonDigitIndex(str, start, len); hour = extractIntValue(str, start, end); //sep = str.charAt(end); //if ( sep != ':' ) { // throw new IllegalArgumentException("expected time to be colon-separated, got '" + sep + "'"); //} start = end + 1; // Skip ':' // minutes end = nonDigitIndex(str, start, len); minute = extractIntValue(str, start, end); //sep = str.charAt(end); //if ( sep != ':' ) { // throw new IllegalArgumentException("expected time to be colon-separated, got '" + sep + "'"); //} start = end + 1; // Skip ':' // seconds end = nonDigitIndex(str, start, len); second = extractIntValue(str, start, end); start = end; // Fractional seconds. if (start < len && str.charAt(start) == '.') { end = nonDigitIndex(str, start + 1, len); // Skip '.' int numlen = end - (start + 1); if (numlen <= 3) { millis = extractIntValue(str, start + 1, end); for (; numlen < 3; ++numlen) millis *= 10; } else { nanos = extractIntValue(str, start + 1, end); for (; numlen < 9; ++numlen) nanos *= 10; } start = end; } start = nonSpaceIndex(str, start, len); // Skip trailing whitespace } // Possibly read timezone. char sep = start < len ? str.charAt(start) : '\0'; if (sep == '+' || sep == '-') { int zoneSign = (sep == '-') ? -1 : 1; int hoursOffset, minutesOffset, secondsOffset; end = nonDigitIndex(str, start + 1, len); // Skip +/- hoursOffset = extractIntValue(str, start + 1, end); start = end; if (start < len && str.charAt(start) == ':') { end = nonDigitIndex(str, start + 1, len); // Skip ':' minutesOffset = extractIntValue(str, start + 1, end); start = end; } else { minutesOffset = 0; } secondsOffset = 0; if (start < len && str.charAt(start) == ':') { end = nonDigitIndex(str, start + 1, len); // Skip ':' secondsOffset = extractIntValue(str, start + 1, end); start = end; } // Setting offset does not seem to work correctly in all // cases.. So get a fresh calendar for a synthetic timezone // instead int offset = zoneSign * hoursOffset * 60; if (offset < 0) { offset = offset - Math.abs(minutesOffset); } else { offset = offset + minutesOffset; } offset = (offset * 60 + secondsOffset) * 1000; zone = DateTimeZone.forOffsetMillis(offset); start = nonSpaceIndex(str, start, len); // Skip trailing whitespace } if (hasDate && start < len) { final char e1 = str.charAt(start); if (e1 == 'A' && str.charAt(start + 1) == 'D') { bcEra = false; start += 2; } else if (e1 == 'B' && str.charAt(start + 1) == 'C') { bcEra = true; start += 2; } } if (start < len) { throw new IllegalArgumentException( "trailing junk: '" + str.substring(start, len - start) + "' on '" + str + "'"); } if (!hasTime && !hasDate) { throw new IllegalArgumentException("'" + str + "' has neither date nor time"); } if (bcEra) year = -1 * year; if (zone == null) { zone = isDefaultTimeZoneUTC(context) ? DateTimeZone.UTC : DateTimeZone.getDefault(); } DateTime dateTime = new DateTime(year, month, day, hour, minute, second, millis, zone); return RubyTime.newTime(context.runtime, dateTime, nanos); }
From source file:azkaban.common.web.GuiUtils.java
License:Apache License
public String getShortTimeZone() { return DateTimeZone.getDefault().getShortName(new DateTime().getMillis()); }
From source file:azkaban.reportal.util.Reportal.java
License:Apache License
public void updateSchedules(Reportal report, ScheduleManager scheduleManager, User user, Flow flow) throws ScheduleManagerException { // Clear previous schedules removeSchedules(scheduleManager);/*from ww w . ja v a2 s. c o m*/ // Add new schedule if (schedule) { int hour = (Integer.parseInt(scheduleHour) % 12) + (scheduleAmPm.equalsIgnoreCase("pm") ? 12 : 0); int minute = Integer.parseInt(scheduleMinute) % 60; DateTimeZone timeZone = scheduleTimeZone.equalsIgnoreCase("UTC") ? DateTimeZone.UTC : DateTimeZone.getDefault(); DateTime firstSchedTime = DateTimeFormat.forPattern("MM/dd/yyyy").withZone(timeZone) .parseDateTime(scheduleDate); firstSchedTime = firstSchedTime.withHourOfDay(hour).withMinuteOfHour(minute).withSecondOfMinute(0) .withMillisOfSecond(0); ReadablePeriod period = null; if (scheduleRepeat) { int intervalQuantity = Integer.parseInt(scheduleIntervalQuantity); if (scheduleInterval.equals("y")) { period = Years.years(intervalQuantity); } else if (scheduleInterval.equals("m")) { period = Months.months(intervalQuantity); } else if (scheduleInterval.equals("w")) { period = Weeks.weeks(intervalQuantity); } else if (scheduleInterval.equals("d")) { period = Days.days(intervalQuantity); } else if (scheduleInterval.equals("h")) { period = Hours.hours(intervalQuantity); } else if (scheduleInterval.equals("M")) { period = Minutes.minutes(intervalQuantity); } } ExecutionOptions options = new ExecutionOptions(); options.getFlowParameters().put("reportal.execution.user", user.getUserId()); options.getFlowParameters().put("reportal.title", report.title); options.getFlowParameters().put("reportal.render.results.as.html", report.renderResultsAsHtml ? "true" : "false"); options.setMailCreator(ReportalMailCreator.REPORTAL_MAIL_CREATOR); scheduleManager.scheduleFlow(-1, project.getId(), project.getName(), flow.getId(), "ready", firstSchedTime.getMillis(), firstSchedTime.getZone(), period, DateTime.now().getMillis(), firstSchedTime.getMillis(), firstSchedTime.getMillis(), user.getUserId(), options, null); } }
From source file:azkaban.webapp.servlet.FlowTriggerInstanceServlet.java
License:Apache License
/** * @param cronTimezone represents the timezone from remote API call * @return if the string is equal to UTC, we return UTC; otherwise, we always return default * timezone./* w w w.ja v a 2 s. com*/ */ private DateTimeZone parseTimeZone(final String cronTimezone) { if (cronTimezone != null && cronTimezone.equals("UTC")) { return DateTimeZone.UTC; } return DateTimeZone.getDefault(); }
From source file:azkaban.webapp.servlet.ScheduleServlet.java
License:Apache License
private DateTime parseDateTime(String scheduleDate, String scheduleTime) { // scheduleTime: 12,00,pm,PDT String[] parts = scheduleTime.split(",", -1); int hour = Integer.parseInt(parts[0]); int minutes = Integer.parseInt(parts[1]); boolean isPm = parts[2].equalsIgnoreCase("pm"); DateTimeZone timezone = parts[3].equals("UTC") ? DateTimeZone.UTC : DateTimeZone.getDefault(); // scheduleDate: 02/10/2013 DateTime day = null;// w w w . j av a 2s.c o m if (scheduleDate == null || scheduleDate.trim().length() == 0) { day = new LocalDateTime().toDateTime(); } else { day = DateTimeFormat.forPattern("MM/dd/yyyy").withZone(timezone).parseDateTime(scheduleDate); } hour %= 12; if (isPm) hour += 12; DateTime firstSchedTime = day.withHourOfDay(hour).withMinuteOfHour(minutes).withSecondOfMinute(0); return firstSchedTime; }