Shuyi Chen | d7955ce | 2013-05-22 14:51:55 -0700 | [diff] [blame] | 1 | /** |
| 2 | * $RCSfile$ |
| 3 | * $Revision$ |
| 4 | * $Date$ |
| 5 | * |
| 6 | * Copyright 2013 Robin Collier. |
| 7 | * |
| 8 | * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | */ |
| 20 | package org.jivesoftware.smack.util; |
| 21 | |
| 22 | import java.text.SimpleDateFormat; |
| 23 | |
| 24 | /** |
| 25 | * Defines the various date and time profiles used in XMPP along with their associated formats. |
| 26 | * |
| 27 | * @author Robin Collier |
| 28 | * |
| 29 | */ |
| 30 | public enum DateFormatType { |
| 31 | // @formatter:off |
| 32 | XEP_0082_DATE_PROFILE("yyyy-MM-dd"), |
| 33 | XEP_0082_DATETIME_PROFILE("yyyy-MM-dd'T'HH:mm:ssZ"), |
| 34 | XEP_0082_DATETIME_MILLIS_PROFILE("yyyy-MM-dd'T'HH:mm:ss.SSSZ"), |
| 35 | XEP_0082_TIME_PROFILE("hh:mm:ss"), |
| 36 | XEP_0082_TIME_ZONE_PROFILE("hh:mm:ssZ"), |
| 37 | XEP_0082_TIME_MILLIS_PROFILE("hh:mm:ss.SSS"), |
| 38 | XEP_0082_TIME_MILLIS_ZONE_PROFILE("hh:mm:ss.SSSZ"), |
| 39 | XEP_0091_DATETIME("yyyyMMdd'T'HH:mm:ss"); |
| 40 | // @formatter:on |
| 41 | |
| 42 | private String formatString; |
| 43 | |
| 44 | private DateFormatType(String dateFormat) { |
| 45 | formatString = dateFormat; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Get the format string as defined in either XEP-0082 or XEP-0091. |
| 50 | * |
| 51 | * @return The defined string format for the date. |
| 52 | */ |
| 53 | public String getFormatString() { |
| 54 | return formatString; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Create a {@link SimpleDateFormat} object with the format defined by {@link #getFormatString()}. |
| 59 | * |
| 60 | * @return A new date formatter. |
| 61 | */ |
| 62 | public SimpleDateFormat createFormatter() { |
| 63 | return new SimpleDateFormat(getFormatString()); |
| 64 | } |
| 65 | } |