View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.logging.log4j.core.util.datetime;
18  
19  import java.text.FieldPosition;
20  import java.util.Calendar;
21  import java.util.Date;
22  import java.util.Locale;
23  import java.util.TimeZone;
24  
25  /**
26   * Copied from Commons Lang 3
27   */
28  public interface DatePrinter {
29  
30      /**
31       * <p>Formats a millisecond {@code long} value.</p>
32       *
33       * @param millis  the millisecond value to format
34       * @return the formatted string
35       * @since 2.1
36       */
37      String format(long millis);
38  
39      /**
40       * <p>Formats a {@code Date} object using a {@code GregorianCalendar}.</p>
41       *
42       * @param date  the date to format
43       * @return the formatted string
44       */
45      String format(Date date);
46  
47      /**
48       * <p>Formats a {@code Calendar} object.</p>
49       * The TimeZone set on the Calendar is only used to adjust the time offset.
50       * The TimeZone specified during the construction of the Parser will determine the TimeZone
51       * used in the formatted string.
52       *
53       * @param calendar  the calendar to format.
54       * @return the formatted string
55       */
56      String format(Calendar calendar);
57  
58      /**
59       * <p>Formats a milliseond {@code long} value into the
60       * supplied {@code StringBuilder}.</p>
61       *
62       * @param millis  the millisecond value to format
63       * @param buf  the buffer to format into
64       * @return the specified string buffer
65       */
66      StringBuilder format(long millis, StringBuilder buf);
67  
68      /**
69       * <p>Formats a {@code Date} object into the
70       * supplied {@code StringBuilder} using a {@code GregorianCalendar}.</p>
71       *
72       * @param date  the date to format
73       * @param buf  the buffer to format into
74       * @return the specified string buffer
75       */
76      StringBuilder format(Date date, StringBuilder buf);
77  
78      /**
79       * <p>Formats a {@code Calendar} object into the supplied {@code StringBuilder}.</p>
80       * The TimeZone set on the Calendar is only used to adjust the time offset.
81       * The TimeZone specified during the construction of the Parser will determine the TimeZone
82       * used in the formatted string.
83       *
84       * @param calendar  the calendar to format
85       * @param buf  the buffer to format into
86       * @return the specified string buffer
87       */
88      StringBuilder format(Calendar calendar, StringBuilder buf);
89  
90      // Accessors
91      //-----------------------------------------------------------------------
92      /**
93       * <p>Gets the pattern used by this printer.</p>
94       *
95       * @return the pattern, {@link java.text.SimpleDateFormat} compatible
96       */
97      String getPattern();
98  
99      /**
100      * <p>Gets the time zone used by this printer.</p>
101      *
102      * <p>This zone is always used for {@code Date} printing. </p>
103      *
104      * @return the time zone
105      */
106     TimeZone getTimeZone();
107 
108     /**
109      * <p>Gets the locale used by this printer.</p>
110      *
111      * @return the locale
112      */
113     Locale getLocale();
114 
115     /**
116      * <p>Formats a {@code Date}, {@code Calendar} or
117      * {@code Long} (milliseconds) object.</p>
118      * 
119      * See {@link java.text.DateFormat#format(Object, StringBuffer, FieldPosition)}
120      * 
121      * @param obj  the object to format
122      * @param toAppendTo  the buffer to append to
123      * @param pos  the position - ignored
124      * @return the buffer passed in
125      */
126     StringBuilder format(Object obj, StringBuilder toAppendTo, FieldPosition pos);
127 }