Example usage for java.util GregorianCalendar get

List of usage examples for java.util GregorianCalendar get

Introduction

In this page you can find the example usage for java.util GregorianCalendar get.

Prototype

public int get(int field) 

Source Link

Document

Returns the value of the given calendar field.

Usage

From source file:org.obm.caldav.obmsync.service.impl.CalendarService.java

private List<DavComponent> getAllLastUpdate(CalDavToken token, String compUrl, DavComponentType componant,
        CompFilter cf) throws Exception {
    Date start = null;//from w w w  . jav  a2 s  .  c o m
    Date end = null;

    if (cf.getTimeRange() != null
            && (cf.getTimeRange().getStart() != null || cf.getTimeRange().getEnd() != null)) {
        start = cf.getTimeRange().getStart();
        end = cf.getTimeRange().getEnd();
        if (start == null) {
            GregorianCalendar gc = new GregorianCalendar();
            gc.set(Calendar.YEAR, gc.get(Calendar.YEAR) - 1);
            start = gc.getTime();
        }

        if (end == null) {
            GregorianCalendar gc = new GregorianCalendar();
            gc.set(Calendar.YEAR, gc.get(Calendar.YEAR) + 1);
            end = gc.getTime();
        }
    } else {
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        cal.setTimeInMillis(0);
        start = cal.getTime();
        end = null;
    }
    AbstractEventSyncClient obmClient = ObmSyncProviderFactory.getInstance().getClient(componant,
            token.getLoginAtDomain());
    AccessToken obmToken = login(obmClient, token);
    List<EventTimeUpdate> items = new ArrayList<EventTimeUpdate>(0);
    try {
        items = obmClient.getEventTimeUpdateNotRefusedFromIntervalDate(obmToken, token.getCalendarName(), start,
                end);
        for (Iterator<EventTimeUpdate> it = items.iterator(); it.hasNext();) {
            EventTimeUpdate ev = it.next();
            if (ev.getRecurrenceId() != null) {
                it.remove();
            }
        }
    } catch (Exception e) {
        throw new Exception();
    } finally {
        logout(obmClient, obmToken);
    }
    return EventConverter.convert(items, compUrl, componant);
}

From source file:com.atolcd.alfresco.web.scripts.shareStats.AuditExportGet.java

/**
 * //from www .j a  v a 2s  .c o m
 * @param timestamp
 *            Date timestamp
 * @param dateInterval
 *            Date interval
 * 
 * @return Date String
 */
public String getStringDate(long timestamp, String dateInterval) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTimeInMillis(timestamp);

    String date = "";
    switch (intervalEnum.valueOf(dateInterval)) {
    case days:
        date = padZero(gc.get(Calendar.HOUR_OF_DAY)) + "h00";
        date += " - ";
        date += padZero((gc.get(Calendar.HOUR_OF_DAY) + 2) % 24) + "h00";
        break;
    case weeks:
        date = padZero(gc.get(Calendar.DAY_OF_MONTH)) + "/";
        date += padZero(gc.get(Calendar.MONTH) + 1) + "/";
        date += String.valueOf(gc.get(Calendar.YEAR));
        break;
    case months:
        date = padZero(gc.get(Calendar.DAY_OF_MONTH)) + "/";
        date += padZero(gc.get(Calendar.MONTH) + 1) + "/";
        date += String.valueOf(gc.get(Calendar.YEAR));
        break;
    case years:
        String monthNumber = String.valueOf(gc.get(Calendar.MONTH));
        date = I18NUtil.getMessage("csv.month." + monthNumber);
        date += " " + String.valueOf(gc.get(Calendar.YEAR));
        break;
    }

    return date;
}

From source file:org.alfresco.provision.AWSService.java

public Metrics getMetrics(String instanceId, List<String> measureNames) {
    GetMetricStatisticsRequest getMetricRequest = new GetMetricStatisticsRequest();
    getMetricRequest.setNamespace("AWS/EC2");
    getMetricRequest.setPeriod(60);//  ww w.  j a va  2s .c o m
    List<String> stats = new LinkedList<>();
    stats.add("Average");
    getMetricRequest.setStatistics(stats);

    getMetricRequest.setNamespace("AWS/EC2");

    Dimension dimension = new Dimension();
    dimension.withName("InstanceId").withValue(instanceId);
    getMetricRequest.setDimensions(Arrays.asList(dimension));

    GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    calendar.add(GregorianCalendar.SECOND, -1 * calendar.get(GregorianCalendar.SECOND));
    getMetricRequest.setEndTime(calendar.getTime());
    calendar.add(GregorianCalendar.MINUTE, -10);
    getMetricRequest.setStartTime(calendar.getTime());

    Map<Long, Metrics> measureSets = new HashMap<>();
    for (String measureName : measureNames) {
        getMetricRequest.setMetricName(measureName);

        GetMetricStatisticsResult metricStatistics = cloudWatchClient.getMetricStatistics(getMetricRequest);
        List<Datapoint> datapoints = metricStatistics.getDatapoints();
        for (Datapoint point : datapoints) {
            Calendar cal = new GregorianCalendar();
            cal.setTime(point.getTimestamp());
            Metrics measureSet = measureSets.get(cal.getTimeInMillis());
            if (measureSet == null) {
                measureSet = new Metrics();
                measureSet.timestamp = cal;
                measureSets.put(cal.getTimeInMillis(), measureSet);
            }
            measureSet.setMetric(measureName, point.getAverage());
        }
    }

    List<Metrics> sortedMeasureSets = new ArrayList<>(measureSets.values());
    if (sortedMeasureSets.size() == 0) {
        return null;
    } else {
        Collections.sort(sortedMeasureSets);
        return sortedMeasureSets.get(sortedMeasureSets.size() - 1);
    }
}

From source file:com.hilllander.naunginlecalendar.view.activity.MainActivity.java

@Override
public void onGridItemClick(int monthDayFlag, GregorianCalendar date) {
    int year = date.get(Calendar.YEAR);
    int month = date.get(Calendar.MONTH);
    int day = date.get(Calendar.DAY_OF_MONTH);
    setCurrentDate(year, month, day);/* w  w  w .  jav a  2s. c om*/

    switch (monthDayFlag) {
    case 0: //click on previous month days
        showCur(SimpleGestureFilter.SWIPE_DOWN);
        break;
    case 1: //click on current month days
        break;
    case 2: //click on next month days
        showCur(SimpleGestureFilter.SWIPE_UP);
        break;
    case 3: // click on selected day
        spinner.setSelection(0, true);
        break;
    }

}

From source file:org.metawidget.swing.widgetprocessor.binding.beanutils.BeanUtilsBindingProcessorTest.java

public void testScalaBinding() throws Exception {

    // Model//from   w w w  .  jav  a  2 s . c o m

    Date dateFirst = new GregorianCalendar(1975, Calendar.APRIL, 9).getTime();

    ScalaFoo scalaFoo = new ScalaFoo();
    scalaFoo.bar_$eq(dateFirst);
    ScalaFoo scalaFoo2 = new ScalaFoo();
    scalaFoo.nestedFoo = scalaFoo2;
    ScalaFoo scalaFoo3 = new ScalaFoo();
    scalaFoo2.nestedFoo = scalaFoo3;
    scalaFoo3.bar_$eq(new GregorianCalendar(1976, Calendar.MAY, 16).getTime());

    // BeanUtilsBinding

    ConvertUtils.register(new DateConverter(DATE_FORMAT), Date.class);

    // Inspect

    SwingMetawidget metawidget = new SwingMetawidget();
    metawidget.addWidgetProcessor(new BeanUtilsBindingProcessor(
            new BeanUtilsBindingProcessorConfig().setPropertyStyle(new ScalaPropertyStyle())));
    BaseObjectInspectorConfig config = new BaseObjectInspectorConfig()
            .setPropertyStyle(new ScalaPropertyStyle());
    metawidget.setInspector(new PropertyTypeInspector(config));
    metawidget.setToInspect(scalaFoo);

    // Loading

    JTextField textField = (JTextField) metawidget.getComponent(1);
    DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
    assertEquals(dateFormat.format(dateFirst), textField.getText());
    JLabel label = (JLabel) metawidget.getComponent(5);
    assertEquals("Not settable", label.getText());

    JTextField nestedTextField = (JTextField) ((SwingMetawidget) metawidget.getComponent(3)).getComponent(1);
    assertEquals("", nestedTextField.getText());

    JTextField nestedNestedTextField = (JTextField) ((SwingMetawidget) ((SwingMetawidget) metawidget
            .getComponent(3)).getComponent(3)).getComponent(1);
    assertEquals(dateFormat.format(scalaFoo3.bar()), nestedNestedTextField.getText());

    // Saving

    Date dateSecond = new GregorianCalendar(1976, Calendar.MAY, 10).getTime();
    textField.setText(dateFormat.format(dateSecond));
    nestedNestedTextField.setText(dateFormat.format(new GregorianCalendar(1977, Calendar.JUNE, 17).getTime()));
    metawidget.getWidgetProcessor(BeanUtilsBindingProcessor.class).save(metawidget);

    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(scalaFoo.bar());
    assertEquals(1976, calendar.get(Calendar.YEAR));
    assertEquals(null, scalaFoo2.bar());
    calendar.setTime(scalaFoo3.bar());
    assertEquals(1977, calendar.get(Calendar.YEAR));

    // Rebinding

    textField = (JTextField) metawidget.getComponent(1);
    assertEquals(dateFormat.format(dateSecond), textField.getText());

    scalaFoo.bar_$eq(dateFirst);
    metawidget.getWidgetProcessor(BeanUtilsBindingProcessor.class).rebind(scalaFoo, metawidget);

    textField = (JTextField) metawidget.getComponent(1);
    assertEquals(dateFormat.format(dateFirst), textField.getText());
}

From source file:com.headstrong.npi.raas.Utils.java

public static CmAttributeDateMonthDay getCmAttrDateMonthDay(String monthDayStr) {
    if (null != monthDayStr && !monthDayStr.trim().isEmpty()) {
        Date date = DateConversion.getDateFromMmDString(monthDayStr);
        if (null != date) {
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTime(date);//from   w ww. j  a  v a  2  s .  com
            XMLGregorianCalendar xmlGregorianCalendar;
            try {
                xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar();
                xmlGregorianCalendar.setMonth(cal.get(Calendar.MONTH) + 1);
                xmlGregorianCalendar.setDay(cal.get(Calendar.DAY_OF_MONTH));
            } catch (DatatypeConfigurationException e) {
                e.printStackTrace();
                return null;
            }
            CmAttributeDateMonthDay cmAttributeDateMonthDay = new CmAttributeDateMonthDay();
            cmAttributeDateMonthDay.setValue(xmlGregorianCalendar);

            return cmAttributeDateMonthDay;
        }
    }
    return null;
}

From source file:com.strider.datadefender.extensions.BiographicFunctions.java

/**
 * Generates random 9-digit social insurance number
 * @return String//from ww w  .java  2 s . c  om
 * @throws java.text.ParseException
 */
public java.sql.Date randomBirthDate() throws java.text.ParseException {
    final GregorianCalendar gc = new GregorianCalendar();
    final int year = randBetween(1900, 2016);

    gc.set(GregorianCalendar.YEAR, year);

    final int dayOfYear = randBetween(1, gc.getActualMaximum(GregorianCalendar.DAY_OF_YEAR));

    gc.set(GregorianCalendar.DAY_OF_YEAR, dayOfYear);

    final String birthDate = prependZero(gc.get(GregorianCalendar.DAY_OF_MONTH)) + "-"
            + prependZero(gc.get(GregorianCalendar.MONTH) + 1) + "-" + gc.get(GregorianCalendar.YEAR);

    log.debug("BirthDate:[" + birthDate + "]");

    final DateFormat format = new SimpleDateFormat("dd-MM-yyyy", Locale.US);
    final java.sql.Date date = new java.sql.Date(format.parse(birthDate).getTime());

    log.debug("Generated BirthDate:[" + date.toString() + "]");

    return date;
}

From source file:org.sakaiproject.calendar.impl.readers.IcalendarReader.java

public List filterEvents(List events, String[] customFieldNames) throws ImportException {
    Iterator it = events.iterator();
    int lineNumber = 1;

    ///*from  w  ww  .j a  va 2  s .  c o  m*/
    // Convert the date/time fields as they appear in the Outlook import to
    // be a synthesized start/end timerange.
    //
    while (it.hasNext()) {
        Map eventProperties = (Map) it.next();

        Date startTime = (Date) eventProperties
                .get(defaultHeaderMap.get(GenericCalendarImporter.START_TIME_DEFAULT_COLUMN_HEADER));
        TimeBreakdown startTimeBreakdown = null;

        if (startTime != null) {
            // if the source time zone were known, this would be
            // a good place to set it: startCal.setTimeZone()
            GregorianCalendar startCal = new GregorianCalendar();
            startCal.setTimeInMillis(startTime.getTime());
            startTimeBreakdown = getTimeService().newTimeBreakdown(0, 0, 0, startCal.get(Calendar.HOUR_OF_DAY),
                    startCal.get(Calendar.MINUTE), startCal.get(Calendar.SECOND), 0);
        } else {
            Integer line = Integer.valueOf(lineNumber);
            String msg = (String) rb.getFormattedMessage("err_no_stime_on", new Object[] { line });
            throw new ImportException(msg);
        }

        Integer durationInMinutes = (Integer) eventProperties
                .get(defaultHeaderMap.get(GenericCalendarImporter.DURATION_DEFAULT_COLUMN_HEADER));

        if (durationInMinutes == null) {
            Integer line = Integer.valueOf(lineNumber);
            String msg = (String) rb.getFormattedMessage("err_no_dtime_on", new Object[] { line });
            throw new ImportException(msg);
        }

        Date endTime = new Date(startTime.getTime() + (durationInMinutes.longValue() * 60 * 1000));

        TimeBreakdown endTimeBreakdown = null;

        if (endTime != null) {
            // if the source time zone were known, this would be
            // a good place to set it: endCal.setTimeZone()
            GregorianCalendar endCal = new GregorianCalendar();
            endCal.setTimeInMillis(endTime.getTime());
            endTimeBreakdown = getTimeService().newTimeBreakdown(0, 0, 0, endCal.get(Calendar.HOUR_OF_DAY),
                    endCal.get(Calendar.MINUTE), endCal.get(Calendar.SECOND), 0);
        }

        Date startDate = (Date) eventProperties
                .get(defaultHeaderMap.get(GenericCalendarImporter.DATE_DEFAULT_COLUMN_HEADER));

        // if the source time zone were known, this would be
        // a good place to set it: startCal.setTimeZone()
        GregorianCalendar startCal = new GregorianCalendar();
        if (startDate != null)
            startCal.setTimeInMillis(startDate.getTime());

        startTimeBreakdown.setYear(startCal.get(Calendar.YEAR));
        startTimeBreakdown.setMonth(startCal.get(Calendar.MONTH) + 1);
        startTimeBreakdown.setDay(startCal.get(Calendar.DAY_OF_MONTH));

        endTimeBreakdown.setYear(startCal.get(Calendar.YEAR));
        endTimeBreakdown.setMonth(startCal.get(Calendar.MONTH) + 1);
        endTimeBreakdown.setDay(startCal.get(Calendar.DAY_OF_MONTH));

        eventProperties.put(GenericCalendarImporter.ACTUAL_TIMERANGE,
                getTimeService().newTimeRange(getTimeService().newTimeLocal(startTimeBreakdown),
                        getTimeService().newTimeLocal(endTimeBreakdown), true, false));

        lineNumber++;
    }

    return events;
}

From source file:com.hilllander.naunginlecalendar.view.activity.MainActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    View tbShadow = findViewById(R.id.home_toolbar_shadow);
    Util.hideToolBarShadowForLollipop(this, toolbar, tbShadow);
    mainLayout = (LinearLayout) findViewById(R.id.main_layout);
    Util.setStatusBarPaddingForKitkat(this, mainLayout);
    setSupportActionBar(toolbar);//from   w  ww. j ava 2  s  .  c o  m
    Util.setSystemUiVisibilityForKitkat(this);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    spinner = (Spinner) findViewById(R.id.spinner);
    ArrayAdapter<CharSequence> arrayAdapter = ArrayAdapter.createFromResource(this, R.array.spinner_item,
            android.R.layout.simple_spinner_item);
    arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(arrayAdapter);
    spinner.setOnItemSelectedListener(new SpinnerListener());
    GregorianCalendar today = new GregorianCalendar();
    setCurrentDate(today.get(Calendar.YEAR), today.get(Calendar.MONTH), today.get(Calendar.DAY_OF_MONTH));
    detecter = new SimpleGestureFilter(this, this);

}

From source file:com.hilllander.naunginlecalendar.view.activity.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();

    if (id == R.id.date_picker) {

        DatePickerDialog datePicker = DatePickerDialog.newInstance(this, currentYear, currentMonth, currentDay);
        datePicker.show(getFragmentManager(), "Datepicker dialog");
    } else if (id == R.id.today) {
        GregorianCalendar cal = new GregorianCalendar();
        int year = cal.get(Calendar.YEAR), month = cal.get(Calendar.MONTH), // Gre month starts from 0
                day = cal.get(Calendar.DAY_OF_MONTH);
        setCurrentDate(year, month, day);
        curJd = kernel.W2J(year, month + 1, day, caltype); // MyanmarCalendar's month starts from 1
        int[] directions = animDirections(SimpleGestureFilter.SWIPE_UP);
        Fragment currentFragment = getCurrentFragment();
        getSupportFragmentManager().beginTransaction().setCustomAnimations(directions[0], directions[1])
                .replace(R.id.main_content, currentFragment).commit();
    } else if (id == R.id.action_license) {
        Intent i = new Intent(MainActivity.this, LicenseActivity.class);
        startActivity(i);//  ww w.j a va 2 s. co  m

    } else if (id == R.id.action_about_us) {
        Intent i = new Intent(MainActivity.this, AboutActivity.class);
        startActivity(i);
    } else if (id == R.id.whatIsNew) {
        WhatNewDialogFragment dialog = new WhatNewDialogFragment();
        dialog.show(getSupportFragmentManager(), "what\'s new dialog");
    } else if (id == R.id.rate_me) {
        Util.rateMe(this);
    }

    return super.onOptionsItemSelected(item);
}