001: /*
002: * $Id: DateAction.java 476710 2006-11-19 05:05:14Z mrdon $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.showcase;
022:
023: import java.text.DateFormat;
024: import java.util.Calendar;
025: import java.util.Date;
026: import java.util.GregorianCalendar;
027:
028: import com.opensymphony.xwork2.ActionSupport;
029:
030: /**
031: * <code>DateAction</code>
032: *
033: */
034: public class DateAction extends ActionSupport {
035:
036: private static DateFormat DF = DateFormat.getDateTimeInstance(
037: DateFormat.MEDIUM, DateFormat.MEDIUM);
038:
039: private Date now;
040: private Date past;
041: private Date future;
042: private Date after;
043: private Date before;
044:
045: public String getDate() {
046: return DF.format(new Date());
047: }
048:
049: /**
050: * @return Returns the future.
051: */
052: public Date getFuture() {
053: return future;
054: }
055:
056: /**
057: * @return Returns the now.
058: */
059: public Date getNow() {
060: return now;
061: }
062:
063: /**
064: * @return Returns the past.
065: */
066: public Date getPast() {
067: return past;
068: }
069:
070: /**
071: *
072: * @return Returns the before date.
073: */
074: public Date getBefore() {
075: return before;
076: }
077:
078: /**
079: *
080: * @return Returns the after date.
081: */
082: public Date getAfter() {
083: return after;
084: }
085:
086: /**
087: */
088: public String browse() throws Exception {
089: Calendar cal = GregorianCalendar.getInstance();
090: now = cal.getTime();
091: cal.roll(Calendar.DATE, -1);
092: cal.roll(Calendar.HOUR, -3);
093: past = cal.getTime();
094: cal.roll(Calendar.DATE, 2);
095: future = cal.getTime();
096:
097: cal.roll(Calendar.YEAR, -1);
098: before = cal.getTime();
099:
100: cal.roll(Calendar.YEAR, 2);
101: after = cal.getTime();
102: return SUCCESS;
103: }
104:
105: }
|