BrightSide Workbench Full Report + Source Code
WdFormats.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.wd.common.entities;
19 
20 import java.io.File;
21 import java.text.ParseException;
22 import java.text.SimpleDateFormat;
23 import java.util.Date;
24 import javax.activation.MimetypesFileTypeMap;
25 
30 public class WdFormats {
31 
32  private static final String DATE_FORMAT = "yyyyMMddHHmm";
33  private static SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
34  public static final MimetypesFileTypeMap MIME_TYPES_FILE_MAP = new MimetypesFileTypeMap();
35 
36  public static Date parse(String date) throws ParseException {
37  return dateFormat.parse(date);
38  }
39 
40  public static String format(Date date) {
41  return dateFormat.format(date);
42  }
43 
44  public static String format(long time) {
45  return dateFormat.format(new Date(time));
46  }
47 
48  public static boolean before(Date date, long time) throws ParseException {
49  return format(date).compareTo(format(time)) > 0;
50  }
51 
52  public static boolean after(Date date, long time) throws ParseException {
53  return format(date).compareTo(format(time)) < 0;
54  }
55 
56  public static String getContentType(File file) {
57  return MIME_TYPES_FILE_MAP.getContentType(file);
58  }
59 
60  public static String getContentType(String file) {
61  return MIME_TYPES_FILE_MAP.getContentType(file);
62  }
63 
64  private WdFormats() {
65  }
66 
67 }
static Date parse(String date)
Definition: WdFormats.java:36
static String getContentType(String file)
Definition: WdFormats.java:60
static final MimetypesFileTypeMap MIME_TYPES_FILE_MAP
Definition: WdFormats.java:34
static String format(Date date)
Definition: WdFormats.java:40
static boolean after(Date date, long time)
Definition: WdFormats.java:52
static String format(long time)
Definition: WdFormats.java:44
static boolean before(Date date, long time)
Definition: WdFormats.java:48
static String getContentType(File file)
Definition: WdFormats.java:56