Example usage for java.util Date getMonth

List of usage examples for java.util Date getMonth

Introduction

In this page you can find the example usage for java.util Date getMonth.

Prototype

@Deprecated
public int getMonth() 

Source Link

Document

Returns a number representing the month that contains or begins with the instant in time represented by this Date object.

Usage

From source file:org.apache.carbondata.processing.merger.CarbonDataMergerUtil.java

/**
 * Method to check if the load dates are complied to the configured dates.
 *
 * @param segDate1// www.  ja  v a  2  s .c  o m
 * @param segDate2
 * @return
 */
private static boolean isTwoDatesPresentInRequiredRange(Date segDate1, Date segDate2,
        long numberOfDaysAllowedToMerge) {
    if (segDate1 == null || segDate2 == null) {
        return false;
    }
    // take 1 st date add the configured days .
    Calendar cal1 = Calendar.getInstance();
    cal1.set(segDate1.getYear(), segDate1.getMonth(), segDate1.getDate());
    Calendar cal2 = Calendar.getInstance();
    cal2.set(segDate2.getYear(), segDate2.getMonth(), segDate2.getDate());

    long diff = cal2.getTimeInMillis() - cal1.getTimeInMillis();

    if ((diff / (24 * 60 * 60 * 1000)) < numberOfDaysAllowedToMerge) {
        return true;
    }
    return false;
}

From source file:org.commoncrawl.mapred.pipelineV3.domainmeta.blogs.postfrequency.ScanDatabaseStep.java

@Override
public void map(TextBytes key, TextBytes jsonMetadata, OutputCollector<TextBytes, HitsByMonth> collector,
        Reporter reporter) throws IOException {

    String url = key.toString();/*from   ww w  .ja va2 s . co m*/

    Matcher topLevelMatcher = topLevelBlogPattern.matcher(url);
    Matcher nestedBlogMatcher = nestedBlogPattern.matcher(url);
    Matcher indexHTMLBlogMatcher = indexHTMLBlogPattern.matcher(url);
    Matcher indexBlogMatcher = indexBlogPattern.matcher(url);
    Matcher nestedIndexHTMLBlogMatcher = nestedIndexHTMLBlogPattern.matcher(url);
    Matcher nestedIndexBlogMatcher = nestedIndexBlogPattern.matcher(url);
    Matcher tumblrPostMatcher = tumblrStyleBlogPattern.matcher(url);

    if (indexHTMLBlogMatcher.matches() && indexHTMLBlogMatcher.groupCount() >= 1) {
        reporter.incrCounter(Counters.MATCHED_INDEX_HTML_PATTERN, 1);
        HitsByMonth hits = new HitsByMonth();
        hits.setFlags(PostFrequencyInfo.Flags.HAS_INDEX_HTML_AFTER_DATE);
        collector.collect(new TextBytes("http://" + indexHTMLBlogMatcher.group(1) + "/"), hits);
    } else if (indexBlogMatcher.matches() && indexBlogMatcher.groupCount() >= 1) {
        reporter.incrCounter(Counters.MATCHED_INDEX_PATTERN, 1);
        HitsByMonth hits = new HitsByMonth();
        hits.setFlags(PostFrequencyInfo.Flags.HAS_YEAR_MONTH_SLASH_INDEX);
        collector.collect(new TextBytes("http://" + indexBlogMatcher.group(1) + "/"), hits);
    } else if (nestedIndexHTMLBlogMatcher.matches() && nestedIndexHTMLBlogMatcher.groupCount() >= 2) {
        reporter.incrCounter(Counters.MATCHED_NESTED_INDEX_HTML_PATTERN, 1);
        HitsByMonth hits = new HitsByMonth();
        hits.setFlags(PostFrequencyInfo.Flags.HAS_INDEX_HTML_AFTER_DATE);
        collector.collect(new TextBytes("http://" + nestedIndexHTMLBlogMatcher.group(1) + "/"
                + nestedIndexHTMLBlogMatcher.group(2) + "/"), hits);
    } else if (nestedIndexBlogMatcher.matches() && nestedIndexBlogMatcher.groupCount() >= 2) {
        reporter.incrCounter(Counters.MATCHED_NESTED_INDEX_PATTERN, 1);
        HitsByMonth hits = new HitsByMonth();
        hits.setFlags(PostFrequencyInfo.Flags.HAS_YEAR_MONTH_SLASH_INDEX);
        collector.collect(new TextBytes(
                "http://" + nestedIndexBlogMatcher.group(1) + "/" + nestedIndexBlogMatcher.group(2) + "/"),
                hits);
    } else if (tumblrPostMatcher.matches() && tumblrPostMatcher.groupCount() >= 2) {
        reporter.incrCounter(Counters.MATCHED_TUMBLR_BLOG_POST_PATTERN, 1);

        String uniqueURL = new String("http://" + tumblrPostMatcher.group(1) + "/");

        try {
            // HACK
            long postId = Long.parseLong(tumblrPostMatcher.group(2));
            long relativeMonth = postId / 1000000000L;
            Date dateStart = new Date(110, 6, 1);
            Date dateOfPost = new Date(dateStart.getTime() + (relativeMonth * 30 * 24 * 60 * 60 * 1000));

            HitsByMonth hits = new HitsByMonth();
            hits.setHitCount(1);
            hits.setYear(dateOfPost.getYear() + 1900);
            hits.setMonth(dateOfPost.getMonth() + 1);

            collector.collect(new TextBytes(uniqueURL), hits);
        } catch (Exception e) {
            reporter.incrCounter(Counters.CAUGHT_EXCEPTION_DURING_TUMBLR_POST_PARSE, 1);
            LOG.error("Exception parsing url:" + url + " Exception:" + StringUtils.stringifyException(e));
        }

    } else if (topLevelMatcher.matches() && topLevelMatcher.groupCount() >= 3) {

        reporter.incrCounter(Counters.MATCHED_TOP_LEVEL_POST_PATTERN, 1);

        String uniqueURL = new String("http://" + topLevelMatcher.group(1) + "/");
        int year = Integer.parseInt(topLevelMatcher.group(2));
        int month = Integer.parseInt(topLevelMatcher.group(3));

        HitsByMonth hits = new HitsByMonth();
        hits.setHitCount(1);
        hits.setYear(year);
        hits.setMonth(month);

        hits.setFlags(scanForGenerator(key, jsonMetadata, reporter));

        collector.collect(new TextBytes(uniqueURL), hits);
    } else if (nestedBlogMatcher.matches() && nestedBlogMatcher.groupCount() >= 4) {

        reporter.incrCounter(Counters.MATCHED_NESTED_POST_PATTERN, 1);

        if (!nestedBlogMatcher.group(1).endsWith("tumblr.com")) {
            String uniqueURL = new String(
                    "http://" + nestedBlogMatcher.group(1) + "/" + nestedBlogMatcher.group(2) + "/");

            int year = Integer.parseInt(nestedBlogMatcher.group(3));
            int month = Integer.parseInt(nestedBlogMatcher.group(4));

            HitsByMonth hits = new HitsByMonth();
            hits.setHitCount(1);
            hits.setYear(year);
            hits.setMonth(month);

            hits.setFlags(scanForGenerator(key, jsonMetadata, reporter));

            collector.collect(new TextBytes(uniqueURL), hits);
        }
    }

}

From source file:eionet.util.Util.java

/**
 *
 * @param timestamp Milliseconds since 1 January 1970.
 *///w  w  w  . j a va  2s . c  o  m
public static String pdfDate(long timestamp) {

    Date date = new Date(timestamp);

    String year = String.valueOf(1900 + date.getYear());
    String month = String.valueOf(date.getMonth() + 1);
    month = (month.length() < 2) ? ("0" + month) : month;
    String day = String.valueOf(date.getDate());
    day = (day.length() < 2) ? ("0" + day) : day;

    return day + "/" + month + "/" + year;
}

From source file:eionet.util.Util.java

/**
 * A method for formatting the given timestamp into a String for history.
 *
 * @param timestamp Milliseconds since 1 January 1970.
 * @return formatted time as string in the form 2015/04/18 12:43.
 *//*from  w w  w.  j a v  a 2s  .com*/
public static String historyDate(long timestamp) {

    Date date = new Date(timestamp);
    String year = String.valueOf(1900 + date.getYear());
    String month = String.valueOf(date.getMonth() + 1);
    month = (month.length() < 2) ? ("0" + month) : month;
    String day = String.valueOf(date.getDate());
    day = (day.length() < 2) ? ("0" + day) : day;
    String hours = String.valueOf(date.getHours());
    hours = (hours.length() < 2) ? ("0" + hours) : hours;
    String minutes = String.valueOf(date.getMinutes());
    minutes = (minutes.length() < 2) ? ("0" + minutes) : minutes;
    String seconds = String.valueOf(date.getSeconds());
    seconds = (seconds.length() < 2) ? ("0" + seconds) : seconds;

    String time = year;
    time = time + "/" + month;
    time = time + "/" + day;
    time = time + " " + hours;
    time = time + ":" + minutes;

    return time;
}

From source file:eionet.util.Util.java

/**
 * A method for formatting the given timestamp into a String released_datasets.jsp.
 *
 * @param timestamp Milliseconds since 1 January 1970.
 *///  w  w w  . j  a v a 2 s  .  co m
private static String releasedDate(long timestamp, boolean shortMonth) {

    Date date = new Date(timestamp);

    String year = String.valueOf(1900 + date.getYear());
    String month = String.valueOf(date.getMonth());
    String day = String.valueOf(date.getDate());
    day = (day.length() < 2) ? ("0" + day) : day;

    Hashtable months = new Hashtable();
    months.put("0", "January");
    months.put("1", "February");
    months.put("2", "March");
    months.put("3", "April");
    months.put("4", "May");
    months.put("5", "June");
    months.put("6", "July");
    months.put("7", "August");
    months.put("8", "September");
    months.put("9", "October");
    months.put("10", "November");
    months.put("11", "December");

    String time = day + " " + (shortMonth ? months.get(month).toString().substring(0, 3) : months.get(month))
            + " " + year;
    return time;
}

From source file:com.eryansky.common.utils.StringUtils.java

/**
 * ???//from   w  ww  .  j  a  v a 2s. c o m
 * 
 * @param time
 * @return
 */
@SuppressWarnings("deprecation")
public static String processTime(Long time) {
    long oneDay = 24 * 60 * 60 * 1000;
    Date now = new Date();
    Date orginalTime = new Date(time);
    long nowDay = now.getTime() - (now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds()) * 1000;
    long yesterday = nowDay - oneDay;
    String nowHourAndMinute = toDoubleDigit(orginalTime.getHours()) + ":"
            + toDoubleDigit(orginalTime.getMinutes());
    if (time >= now.getTime()) {
        return "";
    } else if ((now.getTime() - time) < (60 * 1000)) {
        return (now.getTime() - time) / 1000 + "? " + nowHourAndMinute + " ";
    } else if ((now.getTime() - time) < (60 * 60 * 1000)) {
        return (now.getTime() - time) / 1000 / 60 + "? " + nowHourAndMinute + " ";
    } else if ((now.getTime() - time) < (24 * 60 * 60 * 1000)) {
        return (now.getTime() - time) / 1000 / 60 / 60 + "?? " + nowHourAndMinute + " ";
    } else if (time >= nowDay) {
        return " " + nowHourAndMinute;
    } else if (time >= yesterday) {
        return " " + nowHourAndMinute;
    } else {
        return toDoubleDigit(orginalTime.getMonth()) + "-" + toDoubleDigit(orginalTime.getDate()) + " "
                + nowHourAndMinute + ":" + toDoubleDigit(orginalTime.getSeconds());
    }
}

From source file:kuona.jenkins.analyser.JenkinsProcessor.java

public void collectMetrics(BuildMetrics metrics) {
    try {/*from  w  ww .j  a v a2s.  c  o  m*/
        Utils.puts("Updating " + getURI());
        final int[] jobCount = { 0 };
        final int[] buildCount = { 0 };
        Set<String> jobNames = getJobs().keySet();
        jobCount[0] = jobNames.size();
        jobNames.stream().forEach(key -> {
            try {
                JobWithDetails job = getJob(key);
                Utils.puts("Updating " + key);
                final List<Build> builds = job.details().getBuilds();

                buildCount[0] += builds.size();

                builds.stream().forEach(buildDetails -> {
                    try {
                        final BuildWithDetails details = buildDetails.details();
                        Timestamp timestamp = new Timestamp(details.getTimestamp());

                        Date buildDate = new Date(timestamp.getTime());

                        int year = buildDate.getYear() + 1900;

                        if (!metrics.activity.containsKey(year)) {
                            metrics.activity.put(year, new int[12]);
                        }

                        int[] yearMap = metrics.activity.get(year);
                        yearMap[buildDate.getMonth()] += 1;

                        if (details.getResult() == null) {
                            metrics.buildCountsByResult.put(BuildResult.UNKNOWN,
                                    metrics.buildCountsByResult.get(BuildResult.UNKNOWN) + 1);
                        } else {
                            metrics.buildCountsByResult.put(details.getResult(),
                                    metrics.buildCountsByResult.get(details.getResult()) + 1);
                        }

                        metrics.byDuration.collect(details.getDuration());
                        final List<Map> actions = details.getActions();
                        actions.stream().filter(action -> action != null).forEach(action -> {
                            if (action.containsKey("causes")) {
                                List<HashMap> causes = (List<HashMap>) action.get("causes");

                                causes.stream().filter(cause -> cause.containsKey("shortDescription"))
                                        .forEach(cause -> {
                                            metrics.triggers.add((String) cause.get("shortDescription"));
                                        });
                            }
                        });
                        metrics.completedBuilds.add(details);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                });
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
        metrics.dashboardServers.add(new HashMap<String, Object>() {
            {
                MainView serverInfo = getServerInfo();
                put("name", serverInfo.getName());
                put("description", serverInfo.getDescription());
                put("uri", getURI().toString());
                put("jobs", jobCount[0]);
                put("builds", buildCount[0]);
            }
        });

    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:kuona.processor.JenkinsProcessor.java

public void collectMetrics(BuildMetrics metrics) {
    try {// w  ww . j  a  v a 2  s.  co m
        puts("Updating " + getURI());
        final int[] jobCount = { 0 };
        final int[] buildCount = { 0 };
        Set<String> jobNames = getJobs().keySet();
        jobCount[0] = jobNames.size();
        jobNames.stream().forEach(key -> {
            try {
                JobWithDetails job = getJob(key);
                puts("Updating " + key);
                final List<Build> builds = job.details().getBuilds();

                buildCount[0] += builds.size();

                builds.stream().forEach(buildDetails -> {
                    try {
                        final BuildWithDetails details = buildDetails.details();
                        Timestamp timestamp = new Timestamp(details.getTimestamp());

                        Date buildDate = new Date(timestamp.getTime());

                        int year = buildDate.getYear() + 1900;

                        if (!metrics.activity.containsKey(year)) {
                            metrics.activity.put(year, new int[12]);
                        }

                        int[] yearMap = metrics.activity.get(year);
                        yearMap[buildDate.getMonth()] += 1;

                        if (details.getResult() == null) {
                            metrics.buildCountsByResult.put(BuildResult.UNKNOWN,
                                    metrics.buildCountsByResult.get(BuildResult.UNKNOWN) + 1);
                        } else {
                            metrics.buildCountsByResult.put(details.getResult(),
                                    metrics.buildCountsByResult.get(details.getResult()) + 1);
                        }

                        metrics.byDuration.collect(details.getDuration());
                        final List<Map> actions = details.getActions();
                        actions.stream().filter(action -> action != null).forEach(action -> {
                            if (action.containsKey("causes")) {
                                List<HashMap> causes = (List<HashMap>) action.get("causes");

                                causes.stream().filter(cause -> cause.containsKey("shortDescription"))
                                        .forEach(cause -> {
                                            metrics.triggers.add((String) cause.get("shortDescription"));
                                        });
                            }
                        });
                        metrics.completedBuilds.add(details);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                });
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
        metrics.dashboardServers.add(new HashMap<String, Object>() {
            {
                MainView serverInfo = getServerInfo();
                put("name", serverInfo.getName());
                put("description", serverInfo.getDescription());
                put("uri", getURI().toString());
                put("jobs", jobCount[0]);
                put("builds", buildCount[0]);
            }
        });

    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:org.sakaiproject.myshowcase.tool.MyShowcaseRenderThemeDefault.java

private String renderDefaultDate(Date date) {

    StringBuffer textToInsert = new StringBuffer();

    textToInsert.append("<div class=\"date\">");

    textToInsert.append("<p><strong>" + myshowcaseService.ordinalOfInteger(date.getDate()) + "</strong> "
            + myshowcaseService.shortMonthName(date.getMonth()) + "</p>");

    textToInsert.append("</div>");

    return textToInsert.toString();
}

From source file:org.libreplan.web.costcategories.CostCategoryCRUDController.java

/**
 * Binds Datebox "init date" to the corresponding attribute of a {@link HourCost}
 *
 * @param dateBoxInitDate/*from  www.  j a  v a2s . c om*/
 * @param hourCost
 */
private void bindDateboxEndDate(final Datebox dateBoxEndDate, final HourCost hourCost) {
    Util.bind(dateBoxEndDate, new Util.Getter<Date>() {

        @Override
        public Date get() {
            LocalDate dateTime = hourCost.getEndDate();
            if (dateTime != null) {
                return new Date(dateTime.getYear() - 1900, dateTime.getMonthOfYear() - 1,
                        dateTime.getDayOfMonth());
            }
            return null;
        }

    }, new Util.Setter<Date>() {

        @Override
        public void set(Date value) {
            if (value != null) {
                hourCost.setEndDate(
                        new LocalDate(value.getYear() + 1900, value.getMonth() + 1, value.getDate()));
            } else {
                hourCost.setEndDate(null);
            }
        }
    });
}