Skip to content

Commit 739cc61

Browse files
committed
Add license header, javadoc
1 parent 35dd00e commit 739cc61

File tree

2 files changed

+103
-2
lines changed

2 files changed

+103
-2
lines changed

grails-plugin-gsp/src/main/groovy/org/grails/plugins/web/DefaultGrailsTagDateHelper.groovy

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
1+
/*
2+
* Copyright 2004-2005 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.grails.plugins.web
217

18+
import groovy.transform.CompileStatic
319
import org.apache.commons.lang.time.FastDateFormat
420

5-
21+
/**
22+
* The default implementation of {@link GrailsTagDateHelper}
23+
*
24+
* @author James Kleeh
25+
* @since 3.2.1
26+
* @see GrailsTagDateHelper
27+
*/
28+
@CompileStatic
629
class DefaultGrailsTagDateHelper implements GrailsTagDateHelper {
730

31+
@Override
832
Object getTimeZone(Object timeZone) {
933
if (timeZone != null) {
1034
if (!(timeZone instanceof TimeZone)) {
@@ -17,22 +41,27 @@ class DefaultGrailsTagDateHelper implements GrailsTagDateHelper {
1741
}
1842
}
1943

44+
@Override
2045
Object getFormatFromPattern(String format, Object timeZone, Locale locale) {
2146
FastDateFormat.getInstance(format, (TimeZone)timeZone, locale)
2247
}
2348

49+
@Override
2450
Object getDateFormat(String style, Object timeZone, Locale locale) {
2551
FastDateFormat.getDateInstance(parseStyle(style), (TimeZone)timeZone, locale)
2652
}
2753

54+
@Override
2855
Object getTimeFormat(String style, Object timeZone, Locale locale) {
2956
FastDateFormat.getTimeInstance(parseStyle(style), (TimeZone)timeZone, locale)
3057
}
3158

59+
@Override
3260
Object getDateTimeFormat(String dateStyle, String timeStyle, Object timeZone, Locale locale) {
3361
FastDateFormat.getDateTimeInstance(parseStyle(dateStyle), parseStyle(timeStyle), (TimeZone)timeZone, locale)
3462
}
3563

64+
@Override
3665
String format(Object formatter, Object date) {
3766
((FastDateFormat)formatter).format(date)
3867
}
@@ -46,10 +75,12 @@ class DefaultGrailsTagDateHelper implements GrailsTagDateHelper {
4675
}
4776
}
4877

78+
@Override
4979
Boolean supportsDatePicker(Class clazz) {
5080
clazz == Date
5181
}
5282

83+
@Override
5384
GregorianCalendar buildCalendar(Object date) {
5485
GregorianCalendar c = new GregorianCalendar()
5586
c.setTime((Date)date)
Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,93 @@
1+
/*
2+
* Copyright 2004-2005 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.grails.plugins.web
217

318
/**
4-
* Created by jameskleeh on 10/5/16.
19+
* An interface for defining behavior that Grails tags require surrounding dates
20+
*
21+
* @author James Kleeh
22+
* @since 3.2.1
523
*/
624
interface GrailsTagDateHelper {
725

26+
/**
27+
* Retrieve a time zone object from a parameter
28+
*
29+
* @param timeZone
30+
* @return a time zone to be passed to other methods
31+
*/
832
Object getTimeZone(Object timeZone)
933

34+
/**
35+
* Retrieve a date format object to be passed to the {@link #format} method
36+
*
37+
* @param format The string format pattern
38+
* @param timeZone The timeZone retrieved from {@link #getTimeZone}
39+
* @param locale The locale
40+
*/
1041
Object getFormatFromPattern(String format, Object timeZone, Locale locale)
1142

43+
/**
44+
* Retrieve a date format object without time to be passed to the {@link #format} method
45+
*
46+
* @param style The string type of format //FULL,LONG,MEDIUM,SHORT
47+
* @param timeZone The timeZone retrieved from {@link #getTimeZone}
48+
* @param locale The locale
49+
*/
1250
Object getDateFormat(String style, Object timeZone, Locale locale)
1351

52+
/**
53+
* Retrieve a time format object without time to be passed to the {@link #format} method
54+
*
55+
* @param style The string type of format //FULL,LONG,MEDIUM,SHORT
56+
* @param timeZone The timeZone retrieved from {@link #getTimeZone}
57+
* @param locale The locale
58+
*/
1459
Object getTimeFormat(String style, Object timeZone, Locale locale)
1560

61+
/**
62+
* Retrieve a date format object with time to be passed to the {@link #format} method
63+
*
64+
* @param dateStyle The string type of date format //FULL,LONG,MEDIUM,SHORT
65+
* @param timeStyle The string type of time format //FULL,LONG,MEDIUM,SHORT
66+
* @param timeZone The timeZone retrieved from {@link #getTimeZone}
67+
* @param locale The locale
68+
*/
1669
Object getDateTimeFormat(String dateStyle, String timeStyle, Object timeZone, Locale locale)
1770

71+
/**
72+
* Formats a given date
73+
*
74+
* @param formatter The formatter retrieved from any one of these methods: {@link #getFormatFromPattern}, {@link #getDateFormat}, {@link #getTimeFormat}, {@link #getDateTimeFormat}
75+
* @param date The date to be formatted
76+
* @return The string representation of the date
77+
*/
1878
String format(Object formatter, Object date)
1979

80+
/**
81+
* @param clazz The type of date to be used in a date picker
82+
* @return Whether or not the date is supported by the implementation
83+
*/
2084
Boolean supportsDatePicker(Class clazz)
2185

86+
/**
87+
* Creates a GregorianCalendar based off of the date object. This should only get called if {@link #supportsDatePicker} returns true.
88+
*
89+
* @param date The date to convert
90+
* @return A GregorianCalendar instance
91+
*/
2292
GregorianCalendar buildCalendar(Object date)
2393
}

0 commit comments

Comments
 (0)