Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D01CC200C5E for ; Sat, 22 Apr 2017 14:20:13 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id CEAC8160BAD; Sat, 22 Apr 2017 12:20:13 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 211E0160B93 for ; Sat, 22 Apr 2017 14:20:12 +0200 (CEST) Received: (qmail 85459 invoked by uid 500); 22 Apr 2017 12:20:07 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 85442 invoked by uid 99); 22 Apr 2017 12:20:07 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Apr 2017 12:20:07 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id C0C6DC077B for ; Sat, 22 Apr 2017 12:20:06 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -100.002 X-Spam-Level: X-Spam-Status: No, score=-100.002 tagged_above=-999 required=6.31 tests=[RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id Mj4ZU1n6w80i for ; Sat, 22 Apr 2017 12:20:06 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id A865D60F7A for ; Sat, 22 Apr 2017 12:20:05 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 34A90E0A6C for ; Sat, 22 Apr 2017 12:20:05 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 6E84923FD6 for ; Sat, 22 Apr 2017 12:20:04 +0000 (UTC) Date: Sat, 22 Apr 2017 12:20:04 +0000 (UTC) From: "Pascal Schumacher (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Closed] (LANG-347) DateUtils' new addWeekdays feature MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Sat, 22 Apr 2017 12:20:14 -0000 [ https://issues.apache.org/jira/browse/LANG-347?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Pascal Schumacher closed LANG-347. ---------------------------------- Resolution: Won't Fix As discussed on the mailing list, we won't add new features related to java.util.Date. See https://mail-archives.apache.org/mod_mbox/commons-dev/201704.mbox/%3Cac296ba2-c9ef-2d6f-271e-d4699690581d%40gmx.net%3E for details. > DateUtils' new addWeekdays feature > ---------------------------------- > > Key: LANG-347 > URL: https://issues.apache.org/jira/browse/LANG-347 > Project: Commons Lang > Issue Type: New Feature > Components: lang.time.* > Reporter: Vasily Ivanov > > New method to add signed number of weekdays (skipping weekends): > /** > * Adds a number of weekdays (skipping weekends) to a date returning a new Date object. > * The original date object is unchanged. > *

> * If the original Date itself is on a weekend, calculation will be started from the > * next Monday morning (0:00:00.000) if an amount is positive or from the last Friday night > * (23:59:59.999) otherwise. > * > * @param date the date, not null > * @param amount the amount to add, may be negative > * @return the new Date object with the amount added > */ > public static Date addWeekdays(Date date, > int amount) > { > if (date == null) { > throw new IllegalArgumentException("The date must not be null"); > } > Calendar c = Calendar.getInstance(); > c.setTime(date); > if (amount != 0) { > if (isWeekend(c)) { > // see comments above > final boolean isSat = getDayOfWeek(c) == Calendar.SATURDAY; > int numToJump = 0; > if (amount > 0) { > // this will jump date to the closest Monday > numToJump = isSat ? 2 : 1; > } else { > // this will jump date to the closest Saturday > numToJump = isSat ? 0 : -1; > } > c.add(Calendar.DAY_OF_MONTH, numToJump); > // this will jump to the start of the day (Monday or Saturday) > modify(c, Calendar.DAY_OF_MONTH, false); > if (amount < 0) { > // this will go back to the end of prev Friday > c.add(Calendar.MILLISECOND, -1); > } > } > int count = 0; > final int absAmount = Math.abs(amount); > final int offset = amount > 0 ? 1 : -1; > while (count < absAmount) { > c.add(Calendar.DAY_OF_MONTH, offset); > if (!isWeekend(c)) { > count++; > } > } > } > return c.getTime(); > } > public static int getDayOfWeek(Calendar c) > { > return c.get(Calendar.DAY_OF_WEEK); > } > public static boolean isWeekend(Calendar c) > { > final int dayOfWeek = getDayOfWeek(c); > return dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY; > } -- This message was sent by Atlassian JIRA (v6.3.15#6346)