Source Code Cross Referenced for ISODate.java in  » GIS » geonetwork » org » fao » geonet » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » geonetwork » org.fao.geonet.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //==============================================================================
002:        //===
003:        //===   ISODate
004:        //===
005:        //==============================================================================
006:        //===	Copyright (C) 2001-2007 Food and Agriculture Organization of the
007:        //===	United Nations (FAO-UN), United Nations World Food Programme (WFP)
008:        //===	and United Nations Environment Programme (UNEP)
009:        //===
010:        //===	This program is free software; you can redistribute it and/or modify
011:        //===	it under the terms of the GNU General Public License as published by
012:        //===	the Free Software Foundation; either version 2 of the License, or (at
013:        //===	your option) any later version.
014:        //===
015:        //===	This program is distributed in the hope that it will be useful, but
016:        //===	WITHOUT ANY WARRANTY; without even the implied warranty of
017:        //===	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
018:        //===	General Public License for more details.
019:        //===
020:        //===	You should have received a copy of the GNU General Public License
021:        //===	along with this program; if not, write to the Free Software
022:        //===	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
023:        //===
024:        //===	Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
025:        //===	Rome - Italy. email: geonetwork@osgeo.org
026:        //==============================================================================
027:
028:        package org.fao.geonet.util;
029:
030:        import java.util.Calendar;
031:        import java.util.Date;
032:        import java.util.GregorianCalendar;
033:        import java.util.StringTokenizer;
034:        import java.util.TimeZone;
035:
036:        //==============================================================================
037:
038:        public class ISODate implements  Cloneable {
039:            public int year; //--- 4 digits
040:            public int month; //--- 1..12
041:            public int day; //--- 1..31
042:            public int hour; //--- 0..23
043:            public int min; //--- 0..59
044:            public int sec; //--- 0..59
045:
046:            public boolean isShort; //--- 'true' if the format is yyyy-mm-dd
047:
048:            //---------------------------------------------------------------------------
049:
050:            private static Calendar calendar = Calendar.getInstance();
051:
052:            //---------------------------------------------------------------------------
053:            //---
054:            //--- Constructor
055:            //---
056:            //---------------------------------------------------------------------------
057:
058:            public ISODate() {
059:                this (System.currentTimeMillis());
060:            }
061:
062:            //---------------------------------------------------------------------------
063:
064:            public ISODate(long time) {
065:                synchronized (calendar) {
066:                    calendar.setTimeInMillis(time);
067:
068:                    year = calendar.get(Calendar.YEAR);
069:                    month = calendar.get(Calendar.MONTH) + 1;
070:                    day = calendar.get(Calendar.DAY_OF_MONTH);
071:
072:                    hour = calendar.get(Calendar.HOUR_OF_DAY);
073:                    min = calendar.get(Calendar.MINUTE);
074:                    sec = calendar.get(Calendar.SECOND);
075:                }
076:            }
077:
078:            //---------------------------------------------------------------------------
079:
080:            public ISODate(String isoDate) {
081:                setDate(isoDate);
082:            }
083:
084:            //---------------------------------------------------------------------------
085:
086:            private ISODate(int y, int m, int d, int h, int mi, int s) {
087:                year = y;
088:                month = m;
089:                day = d;
090:                hour = h;
091:                min = mi;
092:                sec = s;
093:            }
094:
095:            //---------------------------------------------------------------------------
096:            //---
097:            //--- API methods
098:            //---
099:            //---------------------------------------------------------------------------
100:
101:            public ISODate clone() {
102:                return new ISODate(year, month, day, hour, min, sec);
103:            }
104:
105:            //---------------------------------------------------------------------------
106:
107:            public void setDate(String isoDate) {
108:                if (isoDate == null)
109:                    throw new IllegalArgumentException("ISO date is null");
110:
111:                if (isoDate.length() < 10)
112:                    throw new IllegalArgumentException("Invalid ISO date : "
113:                            + isoDate);
114:
115:                try {
116:                    year = Integer.parseInt(isoDate.substring(0, 4));
117:                    month = Integer.parseInt(isoDate.substring(5, 7));
118:                    day = Integer.parseInt(isoDate.substring(8, 10));
119:
120:                    isShort = true;
121:
122:                    hour = 0;
123:                    min = 0;
124:                    sec = 0;
125:
126:                    //--- is the date in 'yyyy-mm-dd' or 'yyyy-mm-ddZ' format?
127:
128:                    if (isoDate.length() < 12)
129:                        return;
130:
131:                    isoDate = isoDate.substring(11);
132:
133:                    hour = Integer.parseInt(isoDate.substring(0, 2));
134:                    min = Integer.parseInt(isoDate.substring(3, 5));
135:                    sec = Integer.parseInt(isoDate.substring(6, 8));
136:
137:                    isShort = false;
138:                } catch (Exception e) {
139:                    throw new IllegalArgumentException("Invalid ISO date : "
140:                            + isoDate);
141:                }
142:            }
143:
144:            //---------------------------------------------------------------------------
145:            /** Subtract a date from this date and return the seconds between them */
146:
147:            public long sub(ISODate date) {
148:                return getSeconds() - date.getSeconds();
149:            }
150:
151:            //--------------------------------------------------------------------------
152:
153:            public String getDate() {
154:                return year + "-" + pad(month) + "-" + pad(day);
155:            }
156:
157:            //--------------------------------------------------------------------------
158:
159:            public String getTime() {
160:                return pad(hour) + ":" + pad(min) + ":" + pad(sec);
161:            }
162:
163:            //--------------------------------------------------------------------------
164:
165:            public String toString() {
166:                return getDate() + "T" + getTime();
167:            }
168:
169:            //---------------------------------------------------------------------------
170:
171:            public long getSeconds() {
172:                synchronized (calendar) {
173:                    calendar.clear();
174:                    calendar.set(year, month - 1, day, hour, min, sec);
175:
176:                    return calendar.getTimeInMillis() / 1000;
177:                }
178:            }
179:
180:            //---------------------------------------------------------------------------
181:            //---
182:            //--- Private methods
183:            //---
184:            //---------------------------------------------------------------------------
185:
186:            private String pad(int value) {
187:                if (value > 9)
188:                    return Integer.toString(value);
189:
190:                return "0" + value;
191:            }
192:        }
193:
194:        //==============================================================================
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.