Example usage for java.util GregorianCalendar getTime

List of usage examples for java.util GregorianCalendar getTime

Introduction

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

Prototype

public final Date getTime() 

Source Link

Document

Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch").

Usage

From source file:de.nico.ha_manager.activities.AddHomework.java

private void setTextViewUntil(int[] date) {
    // Format to 31.12.14 or local version of that
    DateFormat f = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
    GregorianCalendar gc = new GregorianCalendar(date[0], date[1], date[2]);
    until = f.format(gc.getTime());

    // Format to Week of Day, for example Mo. or local version of that
    SimpleDateFormat dateFormat = new SimpleDateFormat("EEE", Locale.getDefault());
    String asWeek = dateFormat.format(gc.getTime());

    // Tab space because else the date is too far to the left
    until = (asWeek + ", " + until);
    Button untilButton = (Button) findViewById(R.id.button_until);
    untilButton.setText(until);/*from ww w . j ava2s  .c o  m*/

}

From source file:org.motechproject.mobile.omp.manager.intellivr.ConvertSerializedIVRSessionsBean.java

private Date addToDate(Date start, int field, int amount) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(start);/*from w  w w.j a v a2s .c om*/
    cal.add(field, amount);
    return cal.getTime();
}

From source file:com.jpeterson.littles3.bo.S3Authenticator.java

/**
 * Authenticate the request using the prescribed Amazon S3 authentication
 * mechanisms./* ww  w.j  a  v  a2s .  c  om*/
 * 
 * @param req
 *            The original HTTP request.
 * @param s3Request
 *            The S3 specific information for authenticating the request.
 * @return The authenticated <code>CanonicalUser</code> making the request.
 * @throws RequestTimeTooSkewedException
 *             Thrown if the request timestamp is outside of the allotted
 *             timeframe.
 */
public CanonicalUser authenticate(HttpServletRequest req, S3ObjectRequest s3Request)
        throws AuthenticatorException {
    // check to see if anonymous request
    String authorization = req.getHeader(HEADER_AUTHORIZATION);

    if (authorization == null) {
        return new CanonicalUser(CanonicalUser.ID_ANONYMOUS);
    }

    // attempting to be authenticated request

    if (false) {
        // check timestamp of request
        Date timestamp = s3Request.getTimestamp();
        if (timestamp == null) {
            throw new RequestTimeTooSkewedException("No timestamp provided");
        }

        GregorianCalendar calendar = new GregorianCalendar();
        Date now = calendar.getTime();
        calendar.add(Calendar.MINUTE, 15);
        Date maximumDate = calendar.getTime();
        calendar.add(Calendar.MINUTE, -30);
        Date minimumDate = calendar.getTime();

        if (timestamp.before(minimumDate)) {
            throw new RequestTimeTooSkewedException(
                    "Timestamp [" + timestamp + "] too old. System time: " + now);
        }

        if (timestamp.after(maximumDate)) {
            throw new RequestTimeTooSkewedException(
                    "Timestamp [" + timestamp + "] too new. System time: " + now);
        }
    }

    // authenticate request
    String[] fields = authorization.split(" ");

    if (fields.length != 2) {
        throw new InvalidSecurityException("Unsupported authorization format");
    }

    if (!fields[0].equals(AUTHORIZATION_TYPE)) {
        throw new InvalidSecurityException("Unsupported authorization type: " + fields[0]);
    }

    String[] keys = fields[1].split(":");

    if (keys.length != 2) {
        throw new InvalidSecurityException("Invalid AWSAccesskeyId:Signature");
    }

    String accessKeyId = keys[0];
    String signature = keys[1];
    String secretAccessKey = userDirectory.getAwsSecretAccessKey(accessKeyId);
    String calculatedSignature;

    try {
        SecretKey key = new SecretKeySpec(secretAccessKey.getBytes(), "HmacSHA1");
        Mac m = Mac.getInstance("HmacSHA1");
        m.init(key);
        m.update(s3Request.getStringToSign().getBytes());
        byte[] mac = m.doFinal();
        calculatedSignature = new String(Base64.encodeBase64(mac));
    } catch (NoSuchAlgorithmException e) {
        throw new InvalidSecurityException(e);
    } catch (InvalidKeyException e) {
        throw new InvalidSecurityException(e);
    }

    System.out.println("-----------------");
    System.out.println("signature: " + signature);
    System.out.println("calculatedSignature: " + calculatedSignature);
    System.out.println("-----------------");

    if (calculatedSignature.equals(signature)) {
        // authenticated!
        return userDirectory.getCanonicalUser(secretAccessKey);
    } else {
        throw new SignatureDoesNotMatchException("Provided signature doesn't match calculated value");
    }
}

From source file:org.zephyrsoft.sdb2.model.statistics.SongStatistics.java

private Date wipeTime(Date date) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date);/*  w ww  . j  a va2 s .  c o  m*/
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

From source file:org.chililog.server.workbench.workers.AuthenticationTokenAO.java

/**
 * Updates the expiry date of the token to the current time + number of expiry seconds.
 *//*from w  w  w .  j av  a2 s. c o m*/
public void updateExpiresOn() {
    GregorianCalendar cal = new GregorianCalendar();
    cal.add(Calendar.SECOND, _expirySeconds);
    _expiresOn = cal.getTime();
}

From source file:org.openmrs.module.drughistory.api.DrugEventServiceTest.java

/**
 * @verifies throw exception when sinceWhen is in the future
 * @see DrugEventService#generateDrugEventsFromTrigger(org.openmrs.module.drughistory.DrugEventTrigger, java.util.Date)
 */// w ww . ja  v a  2s  .co  m
@Test
@ExpectedException(IllegalArgumentException.class)
public void generateDrugEventsFromTrigger_shouldThrowExceptionWhenSinceWhenIsInTheFuture() throws Exception {
    GregorianCalendar gc = new GregorianCalendar();
    gc.add(GregorianCalendar.DAY_OF_MONTH, 1);
    AtomicReference<Date> sinceWhen = new AtomicReference<Date>();
    sinceWhen.set(gc.getTime());
    DrugEventTrigger trigger = new DrugEventTrigger();
    drugEventService.generateDrugEventsFromTrigger(trigger, sinceWhen.get());
}

From source file:net.openwatch.acluaz.fragment.DatePickerFragment.java

public void onDateSet(DatePicker view, int year, int month, int day) {
    if (text_field_id == -1)
        return;// ww w.j a v a 2  s .co m

    Calendar c = Calendar.getInstance();
    GregorianCalendar gc = new GregorianCalendar(year, month, day);
    if (this.getActivity().findViewById(text_field_id) != null) {
        ((TextView) this.getActivity().findViewById(text_field_id))
                .setText(Constants.date_formatter.format(gc.getTime()));
        Log.i(TAG, "DatePicker set editText view");
    }
}

From source file:com.projity.server.data.MPXConverter.java

public static void toMpxCalendar(WorkingCalendar workCalendar, ProjectCalendar mpx) {
    mpx.setName(workCalendar.getName());
    //      mpx.setUniqueID((int) workCalendar.getId()); // TODO watch out for int overrun

    WorkingCalendar wc = workCalendar;/*  ww w . j a  v  a 2  s.  c o  m*/
    if (workCalendar.isBaseCalendar())
        wc = (WorkingCalendar) workCalendar.getBaseCalendar();
    for (int i = 0; i < 7; i++) {// MPX days go from SUNDAY=1 to SATURDAY=7
        WorkDay day = workCalendar.isBaseCalendar() ? workCalendar.getDerivedWeekDay(i)
                : workCalendar.getWeekDay(i);
        ProjectCalendarHours mpxDay = null;
        Day d = Day.getInstance(i + 1);
        if (day == null) {
            mpx.setWorkingDay(d, ProjectCalendar.DEFAULT);
        } else {
            mpx.setWorkingDay(d, day.isWorking());
            if (day.isWorking()) {
                mpxDay = mpx.addCalendarHours(Day.getInstance(i + 1));
                toMpxCalendarDay(day, mpxDay);
            }
        }
    }

    WorkDay[] workDays = workCalendar.getExceptionDays();
    if (workDays != null)
        for (int i = 0; i < workDays.length; i++) {
            if (workDays[i] == null || workDays[i].getStart() == 0L || workDays[i].getStart() == Long.MAX_VALUE)
                continue;
            ProjectCalendarException exception = mpx.addCalendarException();
            Date start = new Date(workDays[i].getStart());
            exception.setFromDate(start);
            GregorianCalendar cal = DateTime.calendarInstance();
            // days go from 00:00 to 23:59
            cal.setTime(start);
            cal.set(Calendar.HOUR, 23);
            cal.set(Calendar.MINUTE, 59);
            exception.setToDate(DateTime.fromGmt(cal.getTime()));
            toMpxExceptionDay(workDays[i], exception);
            exception.setWorking(workDays[i].isWorking());
        }
    WorkCalendar baseCalendar = workCalendar.getBaseCalendar();
    if (baseCalendar != null) {
        mpx.setBaseCalendar(ImportedCalendarService.getInstance().findExportedCalendar(baseCalendar));
    }

    //mpx.setUniqueID((int)workCalendar.getUniqueId());
}

From source file:de.arago.rike.task.action.StartTask.java

@Override
public void execute(IDataWrapper data) throws Exception {
    if (data.getRequestAttribute("id") != null) {
        String user = SecurityHelper.getUserEmail(data.getUser());

        if (TaskHelper.getTasksInProgressForUser(user).size() < Integer
                .parseInt(GlobalConfig.get(WORKFLOW_WIP_LIMIT))) {
            Task task = TaskHelper.getTask(data.getRequestAttribute("id"));

            if (!TaskHelper.canDoTask(user, task) || task.getStatusEnum() != Task.Status.OPEN) {
                return;
            }//  w  w  w. j  av a  2s  .  co m

            task.setOwner(user);
            task.setStart(new Date());
            task.setStatus(Task.Status.IN_PROGRESS);
            if (GlobalConfig.get(WORKFLOW_TYPE).equalsIgnoreCase("arago Technologies")) {
                GregorianCalendar c = new GregorianCalendar();
                c.setTime(task.getStart());
                c.add(Calendar.DAY_OF_MONTH, Integer.parseInt(GlobalConfig.get(WORKFLOW_DAYS_TO_FINISH_TASK)));
                task.setDueDate(c.getTime());
            }

            TaskHelper.save(task);
            StatisticHelper.update();

            data.setSessionAttribute("task", task);

            HashMap<String, Object> notificationParam = new HashMap<String, Object>();

            notificationParam.put("id", task.getId().toString());
            data.setEvent("TaskUpdateNotification", notificationParam);

            ActivityLogHelper.log(
                    " started Task #" + task.getId() + " <a href=\"/web/guest/rike/-/show/task/" + task.getId()
                            + "\">" + StringEscapeUtils.escapeHtml(task.getTitle()) + "</a> ",
                    task.getStatus(), user, data, task.toMap());
        }
    }
}

From source file:se.inera.axel.shs.broker.messagestore.internal.AbstractMongoMessageLogTest.java

@BeforeMethod
public void setupTestDB() throws IOException {
    mongoDbFactory.getDb().dropDatabase();

    Maker<se.inera.axel.shs.mime.ShsMessage> asynchMessage = a(ShsMessage,
            with(ShsMessage.label, a(ShsLabel, with(transferType, TransferType.ASYNCH))));

    messageLogService.saveMessage(make(asynchMessage));

    messageLogService.saveMessage(make(asynchMessage));

    messageLogService.messageSent(messageLogService.saveMessage(make(asynchMessage)));

    messageLogService.messageReceived(messageLogService.saveMessage(
            make(a(ShsMessage, with(ShsMessage.label, a(ShsLabel, with(transferType, TransferType.SYNCH)))))));

    messageLogService.messageReceived(messageLogService.saveMessage(make(asynchMessage)));

    messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage,
            with(ShsMessage.label, a(ShsLabel, with(to, a(To, with(To.value, ShsLabelMaker.DEFAULT_TEST_FROM))),
                    with(transferType, TransferType.ASYNCH)))))));

    messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage,
            with(ShsMessage.label, a(ShsLabel, with(product, a(Product, with(Product.value, "error"))),
                    with(sequenceType, SequenceType.ADM), with(transferType, TransferType.ASYNCH)))))));

    messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage,
            with(ShsMessage.label, a(ShsLabel, with(product, a(Product, with(Product.value, "confirm"))),
                    with(sequenceType, SequenceType.ADM), with(transferType, TransferType.ASYNCH)))))));

    messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage, with(ShsMessage.label,
            a(ShsLabel, with(transferType, TransferType.ASYNCH), with(status, Status.TEST)))))));

    messageLogService.messageAcknowledged(
            messageLogService.messageReceived(messageLogService.saveMessage(make(asynchMessage))));

    messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage,
            with(ShsMessage.label, a(ShsLabel, with(to, a(To, with(To.value, ShsLabelMaker.DEFAULT_TEST_FROM))),
                    with(endRecipient,/*ww w. j  a  v  a  2  s  .co  m*/
                            a(EndRecipient, with(EndRecipient.value, ShsLabelMaker.DEFAULT_TEST_ENDRECIPIENT))),
                    with(transferType, TransferType.ASYNCH)))))));

    messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage,
            with(ShsMessage.label, a(ShsLabel, with(to, a(To, with(To.value, ShsLabelMaker.DEFAULT_TEST_FROM))),
                    with(corrId, "testing-corrid"), with(transferType, TransferType.ASYNCH)))))));

    messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage,
            with(ShsMessage.label,
                    a(ShsLabel, with(to, a(To, with(To.value, ShsLabelMaker.DEFAULT_TEST_FROM))),
                            with(transferType, TransferType.ASYNCH),
                            with(content, a(Content, with(Content.contentId, "testing-contentid")))))))));

    messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage,
            with(ShsMessage.label, a(ShsLabel, with(to, a(To, with(To.value, ShsLabelMaker.DEFAULT_TEST_FROM))),
                    with(transferType, TransferType.ASYNCH),
                    with(meta, listOf(a(Meta, with(Meta.name, "namn"), with(Meta.value, "varde"))))))))));

    messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage,
            with(ShsMessage.label, a(ShsLabel, with(originatorOrFrom,
                    listOf(a(Originator, with(Originator.value, ShsLabelMaker.DEFAULT_TEST_ORIGINATOR)))),
                    with(to, a(To, with(To.value, ShsLabelMaker.DEFAULT_TEST_FROM))),
                    with(transferType, TransferType.ASYNCH)))))));

    ShsMessageEntry entry = messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage,
            with(ShsMessage.label, a(ShsLabel, with(to, a(To, with(To.value, ShsLabelMaker.DEFAULT_TEST_FROM))),
                    with(subject, "lastWeeksMessage"), with(transferType, TransferType.ASYNCH)))))));

    //config for message "entry"

    GregorianCalendar lastWeek = new GregorianCalendar();
    lastWeek.add(GregorianCalendar.DAY_OF_MONTH, -7);

    entry.setStateTimeStamp(lastWeek.getTime());
    messageLogService.update(entry);

    entry = messageLogService.saveMessage(make(asynchMessage));

    messageLogService.update(entry);

    mongoOperations.indexOps(ShsMessageEntry.class)
            .ensureIndex(new Index().on("label.txId", Sort.Direction.ASC).unique());
}