Example usage for java.util Calendar HOUR

List of usage examples for java.util Calendar HOUR

Introduction

In this page you can find the example usage for java.util Calendar HOUR.

Prototype

int HOUR

To view the source code for java.util Calendar HOUR.

Click Source Link

Document

Field number for get and set indicating the hour of the morning or afternoon.

Usage

From source file:net.navasoft.madcoin.backend.services.rest.impl.OrdersService.java

/**
 * Gets the available requests.//from  w  ww.ja  v  a2 s. com
 * 
 * @param userType
 *            the user type
 * @param filter
 *            the filter
 * @return the available requests
 * @since 31/08/2014, 02:50:04 PM
 */
@Override
public WorkRequestListVO getAvailableRequests(String userType, IFilteredFields<?, ?, ?> filter) {
    WorkRequestListVO list = new WorkRequestListVO();
    int orderAmount = Calendar.getInstance().get(Calendar.HOUR);
    do {
        WorkRequestVO order = new WorkRequestVO();
        order.setOrderLocation("Carrera 15 # 82 -51 Of. 204");
        order.setOrderLocationDetails("Vision-AR Office - Mancho Nieto");
        order.setOrderStatus(OrderStatus.REGISTERED);
        order.setSubCategory("GENERAL CARE");
        String llaveUsuario = EFilters.getSpecificProperty("username", 0);
        Calendar orderDate = Calendar.getInstance();
        orderDate.add(Calendar.HOUR, -orderAmount);
        order.setOrderGeneration(orderDate.getTime());
        String lob = (orderDate.get(Calendar.MINUTE) % 2 == 0 ? "HOME" : "BEAUTY");
        order.setRequestIdentifier(MessageFormat.format("{0}-{1}-{2}", lob, "GENERAL CARE", orderAmount));
        order.setCategory(lob);
        if (filter != null) {
            if (!filter.getFilteredFields().isEmpty() && filter.getFilteredFields().containsKey(llaveUsuario)) {
                order.setUsernameRequester((String) filter.getFilteredFields().get(llaveUsuario));
            } else {
                order = randomize(orderAmount,
                        Math.abs(orderDate.get(Calendar.SECOND) - orderDate.get(Calendar.MINUTE)), order);
            }
        } else {
            order = randomize(orderAmount, orderDate.get(Calendar.SECOND), order);
        }
        order.setOrderSummary("Test!!!");
        list.addWorkRequest(order);
        orderAmount--;
    } while (orderAmount > 0);
    return list;
}

From source file:ch.cyberduck.core.azure.AzurePath.java

public DescriptiveUrl toSignedUrl() {
    ResourceType type;/* w w w . j a  v a  2 s. com*/
    if (this.isContainer()) {
        type = ResourceType.Container;
    } else {
        type = ResourceType.Blob;
    }
    Date now = new Date();
    Calendar expiry = Calendar.getInstance();
    expiry.setTime(now);
    // If a signed identifier is not specified as part of the Shared Access Signature, the maximum
    // permissible interval over which the signature is valid is one hour. This limit ensures
    // that a signature that is not bound to a container-level access policy is valid for a
    // short duration.
    expiry.add(Calendar.HOUR, 1);
    try {
        final String signedidentifier = null; // Optional. A unique value that correlates to an access policy
        // specified at the container level. The signed identifier may have a maximum size of 64 characters.
        final ISharedAccessUrl shared = this.getSession().getClient().createSharedAccessUrl(
                this.getContainerName(), this.getKey(), type, SharedAccessPermissions.RL, null, // If the signature does not provide a value for the signedstart field, the
                // start time is assumed to be the time when the request reaches the Blob service.
                new DateTime(expiry.getTime()), signedidentifier);
        return new DescriptiveUrl(shared.getRestUrl(),
                MessageFormat.format(Locale.localizedString("Expires on {0}", "S3"),
                        DateFormatterFactory.instance().getLongFormat(expiry.getTimeInMillis())));
    } catch (ConnectionCanceledException e) {
        log.warn(e.getMessage());
    }
    return new DescriptiveUrl(null, null);
}

From source file:DateUtils.java

/**
 * Get expiration timestamp from start date, period type and duration. For 
 * example if the start date is now, period type is hour and duration is 2
 * then the result will be timestamp representing now + 2 hours.  
 * /* w  w w.  j ava2s  .  c  om*/
 * @param tsStartDate - start date of period counting
 * @param iPeriodType - one of the period type constant TIMING_XXX 
 * @param iPeriodDuration - period duration, number of time units specified 
 *                          by period type
 * @return Timestamp - date of period expiration or null if any problem
 */
public static Timestamp getPeriodExpiration(Timestamp tsStartDate, int iPeriodType, int iPeriodDuration) {
    Timestamp tsReturn = null;
    Calendar calHelp;
    if (tsStartDate != null && iPeriodDuration > 0 && iPeriodType > TIMING_NEVER && iPeriodType < TIMING_NONE) {
        calHelp = Calendar.getInstance();
        calHelp.setTime(tsStartDate);

        switch (iPeriodType) {
        case (TIMING_MINUTES): {
            calHelp.add(Calendar.MINUTE, iPeriodDuration);
            break;
        }
        case (TIMING_HOURS): {
            calHelp.add(Calendar.HOUR, iPeriodDuration);
            break;
        }
        case (TIMING_DAYS): {
            calHelp.add(Calendar.DATE, iPeriodDuration);
            break;
        }
        case (TIMING_WEEKS): {
            calHelp.add(Calendar.WEEK_OF_YEAR, iPeriodDuration);
            break;
        }
        case (TIMING_MONTHS): {
            calHelp.add(Calendar.MONTH, iPeriodDuration);
            break;
        }
        case (TIMING_YEARS): {
            calHelp.add(Calendar.YEAR, iPeriodDuration);
            break;
        }
        default: {
            assert false : "Not supported Timing type " + iPeriodType;
        }
        }
        tsReturn = new Timestamp(calHelp.getTimeInMillis());
    }

    return tsReturn;
}

From source file:com.akretion.kettle.steps.terminatooor.ScriptValuesAddedFunctions.java

public static Object dateAdd(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
        Object FunctionContext) {
    if (ArgList.length == 3) {
        try {//from   w  w w.j a  va2s  .  co  m
            if (isNull(ArgList, new int[] { 0, 1, 2 }))
                return null;
            else if (isUndefined(ArgList, new int[] { 0, 1, 2 }))
                return undefinedValue;
            java.util.Date dIn = (java.util.Date) ArgList[0];
            String strType = (String) ArgList[1];
            int iValue = (int) (Integer) ArgList[2];
            Calendar cal = Calendar.getInstance();
            cal.setTime(dIn);
            if (strType.toLowerCase().equals("y"))
                cal.add(Calendar.YEAR, iValue);
            else if (strType.toLowerCase().equals("m"))
                cal.add(Calendar.MONTH, iValue);
            else if (strType.toLowerCase().equals("d"))
                cal.add(Calendar.DATE, iValue);
            else if (strType.toLowerCase().equals("w"))
                cal.add(Calendar.WEEK_OF_YEAR, iValue);
            else if (strType.toLowerCase().equals("wd")) {
                int iOffset = 0;
                while (iOffset < iValue) {
                    int day = cal.get(Calendar.DAY_OF_WEEK);
                    cal.add(Calendar.DATE, 1);
                    if ((day != Calendar.SATURDAY) && (day != Calendar.SUNDAY))
                        iOffset++;
                }
            } else if (strType.toLowerCase().equals("hh"))
                cal.add(Calendar.HOUR, iValue);
            else if (strType.toLowerCase().equals("mi"))
                cal.add(Calendar.MINUTE, iValue);
            else if (strType.toLowerCase().equals("ss"))
                cal.add(Calendar.SECOND, iValue);
            return cal.getTime();
        } catch (Exception e) {
            throw new RuntimeException(e.toString());
        }
    } else {
        throw new RuntimeException("The function call dateAdd requires 3 arguments.");
    }
}

From source file:com.concursive.connect.web.modules.calendar.utils.CalendarView.java

/**
 * Returns true if today is the current calendar day being drawn
 *
 * @param tmp    Description of Parameter
 * @param indate Description of Parameter
 * @return The CurrentDay value/*from   w  w w . ja va2 s  .  c o m*/
 */
public boolean isCurrentDay(Calendar tmp, int indate) {
    Calendar thisMonth = Calendar.getInstance(locale);
    thisMonth.set(Calendar.HOUR, 0);
    thisMonth.set(Calendar.MINUTE, 0);
    thisMonth.set(Calendar.SECOND, 0);
    thisMonth.set(Calendar.MILLISECOND, 0);
    if (timeZone != null) {
        thisMonth.setTimeZone(timeZone);
    }
    if ((indate == thisMonth.get(Calendar.DAY_OF_MONTH))
            && (tmp.get(Calendar.MONTH) == thisMonth.get(Calendar.MONTH))
            && (tmp.get(Calendar.YEAR) == thisMonth.get(Calendar.YEAR))) {
        return true;
    } else {
        return false;
    }
}

From source file:free.yhc.feeder.model.Utils.java

/**
 * NOTE//from ww w.j  a v a 2 s.c  o m
 * 'secs' array is [in/out] argument.
 * @param calNow
 * @param secs
 *   [in/out] After return, array is sorted by ascending numerical order.
 *   00:00:00 based value.
 *   seconds since 00:00:00 (12:00 AM)
 *   (negative value is NOT ALLOWED)
 *   Order may be changed (sorted) to ascending order.
 * @return
 *   time(ms based on 1970) to next nearest time of given second-of-day array.
 */
public static long nextNearestTime(Calendar calNow, long[] secs) {
    eAssert(secs.length > 0);
    Calendar cal = Calendar.getInstance();
    cal.setTime(calNow.getTime());

    long now = cal.getTimeInMillis();
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    long dayBase = cal.getTimeInMillis();
    long dayTime = now - dayBase;
    if (dayTime < 0)
        dayTime = 0; // To compensate error from '/' operation.

    Arrays.sort(secs);
    // Just linear search... it's enough.
    // Binary search is not considered yet.(over-engineering)
    for (long s : secs) {
        eAssert(s >= 0);
        if (s * 1000 > dayTime)
            return dayTime + s * 1000;
    }
    // All scheduled time is passed for day.
    // smallest of tomorrow is nearest one.
    return dayBase + DAY_IN_MS + secs[0] * 1000;
}

From source file:com.ecofactor.qa.automation.drapi.DRAPI_Test.java

/**
 * String value is common for few test cases were depends on gateway id.
 * @param targetJson is targetJson/*from www  .j  a v  a  2 s  . c o m*/
 * @param gatewayID is gatewayID
 * @return String
 */
public String gatewayJson(final String url, final String targetJson, final String gatewayID) {

    String json = targetJson;
    json = json.replaceFirst("<gateway_id>", gatewayID)
            .replaceFirst("<start_time>",
                    Long.toString(DateUtil.subtractFromUTCMilliSeconds(Calendar.MINUTE, 5)))
            .replaceFirst("<end_time>", Long.toString(DateUtil.addToUTCMilliSeconds(Calendar.HOUR, 1)));
    setLogString("URL Values of the API \n" + url + "\n" + json, true);
    return json;
}

From source file:com.panet.imeta.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java

public static Object dateAdd(Context actualContext, Scriptable actualObject, Object[] ArgList,
        Function FunctionContext) {
    if (ArgList.length == 3) {
        try {//from  ww w.jav  a 2 s . c  o  m
            if (isNull(ArgList, new int[] { 0, 1, 2 }))
                return null;
            else if (isUndefined(ArgList, new int[] { 0, 1, 2 }))
                return Context.getUndefinedValue();
            java.util.Date dIn = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class);
            String strType = Context.toString(ArgList[1]);
            int iValue = (int) Context.toNumber(ArgList[2]);
            Calendar cal = Calendar.getInstance();
            cal.setTime(dIn);
            if (strType.toLowerCase().equals("y"))
                cal.add(Calendar.YEAR, iValue);
            else if (strType.toLowerCase().equals("m"))
                cal.add(Calendar.MONTH, iValue);
            else if (strType.toLowerCase().equals("d"))
                cal.add(Calendar.DATE, iValue);
            else if (strType.toLowerCase().equals("w"))
                cal.add(Calendar.WEEK_OF_YEAR, iValue);
            else if (strType.toLowerCase().equals("wd")) {
                int iOffset = 0;
                while (iOffset < iValue) {
                    int day = cal.get(Calendar.DAY_OF_WEEK);
                    cal.add(Calendar.DATE, 1);
                    if ((day != Calendar.SATURDAY) && (day != Calendar.SUNDAY))
                        iOffset++;
                }
            } else if (strType.toLowerCase().equals("hh"))
                cal.add(Calendar.HOUR, iValue);
            else if (strType.toLowerCase().equals("mi"))
                cal.add(Calendar.MINUTE, iValue);
            else if (strType.toLowerCase().equals("ss"))
                cal.add(Calendar.SECOND, iValue);
            return cal.getTime();
        } catch (Exception e) {
            throw Context.reportRuntimeError(e.toString());
        }
    } else {
        throw Context.reportRuntimeError("The function call dateAdd requires 3 arguments.");
    }
}

From source file:com.microsoftopentechnologies.windowsazurestorage.WAStorageClient.java

public static SharedAccessBlobPolicy generatePolicy() {
    SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy();
    GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    calendar.setTime(new Date());

    calendar.add(Calendar.HOUR, 1);
    policy.setSharedAccessExpiryTime(calendar.getTime());
    policy.setPermissions(EnumSet.of(SharedAccessBlobPermissions.READ));

    return policy;
}

From source file:net.navasoft.madcoin.backend.services.rest.impl.OrdersService.java

/**
 * Gets the all requests by segment./*from   w  w  w  .j  a v a 2  s  .c om*/
 * 
 * @param userType
 *            the user type
 * @param business_line
 *            the business_line
 * @param service_category
 *            the service_category
 * @return the all requests by segment
 * @since 31/08/2014, 02:50:04 PM
 */
@Override
public WorkRequestListVO getAllRequestsBySegment(String userType, String business_line,
        String service_category) {
    WorkRequestListVO list = new WorkRequestListVO();
    int orderAmount = Calendar.getInstance().get(Calendar.HOUR);
    do {
        WorkRequestVO order = new WorkRequestVO();
        order.setRequestIdentifier(
                MessageFormat.format("{0}-{1}-{2}", business_line, service_category, orderAmount));
        order.setCategory(business_line);
        order.setSubCategory(service_category);
        order.setOrderLocation("Carrera 26 # 27A - 13 Sur");
        order.setOrderLocationDetails("Click -n- Done CTO - Master Developer");
        order.setUsernameRequester("jnavarre");
        Calendar orderDate = Calendar.getInstance();
        orderDate.add(Calendar.HOUR, -orderAmount);
        order.setOrderGeneration(orderDate.getTime());
        order.setOrderStatus(orderDate.get(Calendar.HOUR_OF_DAY) % 2 == 0 ? OrderStatus.REGISTERED
                : OrderStatus.CANCELLED_BY_USER);
        order.setOrderSummary("Asking for Blowjob...");
        list.addWorkRequest(order);
        orderAmount--;
    } while (orderAmount > 0);
    return list;
}