Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
d1514e17
提交
d1514e17
authored
12月 22, 2015
作者:
Patrick Brielmayer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Renamed constants to match Java convention
上级
0c7d6634
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
72 行增加
和
72 行删除
+72
-72
ToDateTokenizer.java
h2/src/main/org/h2/util/ToDateTokenizer.java
+72
-72
没有找到文件。
h2/src/main/org/h2/util/ToDateTokenizer.java
浏览文件 @
d1514e17
...
...
@@ -16,64 +16,64 @@ import org.h2.message.DbException;
* This class knows all about the TO_DATE-format conventions and how to parse the corresponding data
*/
class
ToDateTokenizer
{
private
static
final
Pattern
PATTERN_N
umber
=
Pattern
.
compile
(
"^([+-]?[0-9]+)"
);
private
static
final
Pattern
PATTERN_
4_Digit
=
Pattern
.
compile
(
"^([+-]?[0-9]{4})"
);
private
static
final
Pattern
PATTERN_
3_Digit
=
Pattern
.
compile
(
"^([+-]?[0-9]{3})"
);
private
static
final
Pattern
PATTERN_
2_Digit
=
Pattern
.
compile
(
"^([+-]?[0-9]{2})"
);
private
static
final
Pattern
PATTERN_
2_DigitOrLess
=
Pattern
.
compile
(
"^([+-]?[0-9][0-9]?)"
);
private
static
final
Pattern
PATTERN_
1_Digit
=
Pattern
.
compile
(
"^([+-]?[0-9])"
);
private
static
final
Pattern
PATTERN_N
UMBER
=
Pattern
.
compile
(
"^([+-]?[0-9]+)"
);
private
static
final
Pattern
PATTERN_
FOUR_DIGITS
=
Pattern
.
compile
(
"^([+-]?[0-9]{4})"
);
private
static
final
Pattern
PATTERN_
THREE_DIGITS
=
Pattern
.
compile
(
"^([+-]?[0-9]{3})"
);
private
static
final
Pattern
PATTERN_
TWO_DIGITS
=
Pattern
.
compile
(
"^([+-]?[0-9]{2})"
);
private
static
final
Pattern
PATTERN_
TWO_DIGITS_OR_LESS
=
Pattern
.
compile
(
"^([+-]?[0-9][0-9]?)"
);
private
static
final
Pattern
PATTERN_
ONE_DIGIT
=
Pattern
.
compile
(
"^([+-]?[0-9])"
);
private
static
final
Pattern
PATTERN_FF
=
Pattern
.
compile
(
"^(FF[0-9]?)"
,
Pattern
.
CASE_INSENSITIVE
);
private
static
final
Pattern
PATTERN_AM_PM
=
Pattern
.
compile
(
"^(AM|A\\.M\\.|PM|P\\.M\\.)"
,
Pattern
.
CASE_INSENSITIVE
);
private
static
final
Pattern
PATTERN_BC_AD
=
Pattern
.
compile
(
"^(BC|B\\.C\\.|AD|A\\.D\\.)"
,
Pattern
.
CASE_INSENSITIVE
);
private
static
final
YearParslet
PARSLET_Y
ear
=
new
YearParslet
();
private
static
final
MonthParslet
PARSLET_M
onth
=
new
MonthParslet
();
private
static
final
YearParslet
PARSLET_Y
EAR
=
new
YearParslet
();
private
static
final
MonthParslet
PARSLET_M
ONTH
=
new
MonthParslet
();
//private static final WeekParslet PARSLET_Week = new WeekParslet();
private
static
final
DayParslet
PARSLET_D
ay
=
new
DayParslet
();
private
static
final
TimeParslet
PARSLET_T
ime
=
new
TimeParslet
();
private
static
final
DayParslet
PARSLET_D
AY
=
new
DayParslet
();
private
static
final
TimeParslet
PARSLET_T
IME
=
new
TimeParslet
();
static
enum
FormatTokenEnum
{
YYYY
(
PARSLET_Y
ear
)
// 4-digit year
,
SYYYY
(
PARSLET_Y
ear
)
// 4-digit year with sign (- = B.C.)
,
IYYY
(
PARSLET_Y
ear
)
// 4-digit year based on the ISO standard (?)
,
YYY
(
PARSLET_Y
ear
)
//
,
IYY
(
PARSLET_Y
ear
)
//
,
YY
(
PARSLET_Y
ear
)
//
,
IY
(
PARSLET_Y
ear
)
//
,
SCC
(
PARSLET_Y
ear
)
// Two-digit century with with sign (- = B.C.)
,
CC
(
PARSLET_Y
ear
)
// Two-digit century.
,
RRRR
(
PARSLET_Y
ear
)
// 2-digit -> 4-digit year 0-49 -> 20xx , 50-99 -> 19xx
,
RR
(
PARSLET_Y
ear
)
// last 2-digit of the year using "current" century value.
,
BC_AD
(
PARSLET_Y
ear
,
PATTERN_BC_AD
)
// Meridian indicator
,
MONTH
(
PARSLET_M
onth
)
// Full Name of month
,
MON
(
PARSLET_M
onth
)
// Abbreviated name of month.
,
MM
(
PARSLET_M
onth
)
// Month (01-12; JAN = 01).
,
RM
(
PARSLET_M
onth
)
// Roman numeral month (I-XII; JAN = I).
YYYY
(
PARSLET_Y
EAR
)
// 4-digit year
,
SYYYY
(
PARSLET_Y
EAR
)
// 4-digit year with sign (- = B.C.)
,
IYYY
(
PARSLET_Y
EAR
)
// 4-digit year based on the ISO standard (?)
,
YYY
(
PARSLET_Y
EAR
)
//
,
IYY
(
PARSLET_Y
EAR
)
//
,
YY
(
PARSLET_Y
EAR
)
//
,
IY
(
PARSLET_Y
EAR
)
//
,
SCC
(
PARSLET_Y
EAR
)
// Two-digit century with with sign (- = B.C.)
,
CC
(
PARSLET_Y
EAR
)
// Two-digit century.
,
RRRR
(
PARSLET_Y
EAR
)
// 2-digit -> 4-digit year 0-49 -> 20xx , 50-99 -> 19xx
,
RR
(
PARSLET_Y
EAR
)
// last 2-digit of the year using "current" century value.
,
BC_AD
(
PARSLET_Y
EAR
,
PATTERN_BC_AD
)
// Meridian indicator
,
MONTH
(
PARSLET_M
ONTH
)
// Full Name of month
,
MON
(
PARSLET_M
ONTH
)
// Abbreviated name of month.
,
MM
(
PARSLET_M
ONTH
)
// Month (01-12; JAN = 01).
,
RM
(
PARSLET_M
ONTH
)
// Roman numeral month (I-XII; JAN = I).
//, WW(PARSLET_Week) // Week of year (1-53)
//, IW(PARSLET_Week) // Week of year (1-52 or 1-53) based on the ISO standard.
,
DDD
(
PARSLET_D
ay
)
// Day of year (1-366).
,
DAY
(
PARSLET_D
ay
)
// Name of day.
,
DD
(
PARSLET_D
ay
)
// Day of month (1-31).
,
DY
(
PARSLET_D
ay
)
// Abbreviated name of day.
,
HH24
(
PARSLET_T
ime
)
//
,
HH12
(
PARSLET_T
ime
)
//
,
HH
(
PARSLET_T
ime
)
// Hour of day (1-12).
,
MI
(
PARSLET_T
ime
)
// Min
,
SSSSS
(
PARSLET_T
ime
)
// Seconds past midnight (0-86399)
,
SS
(
PARSLET_T
ime
)
//
,
FF
(
PARSLET_T
ime
,
PATTERN_FF
)
// Fractional seconds
,
TZH
(
PARSLET_T
ime
)
// Time zone hour.
,
TZM
(
PARSLET_T
ime
)
// Time zone minute.
,
TZR
(
PARSLET_T
ime
)
// Time zone region ID
,
TZD
(
PARSLET_T
ime
)
// Daylight savings information. Example: PST (for US/Pacific standard time);
,
AM_PM
(
PARSLET_T
ime
,
PATTERN_AM_PM
)
// Meridian indicator
,
EE
(
PARSLET_Y
ear
)
// NOT supported yet - Full era name (Japanese Imperial, ROC Official, and Thai Buddha calendars).
,
E
(
PARSLET_Y
ear
)
// NOT supported yet - Abbreviated era name (Japanese Imperial, ROC Official, and Thai Buddha calendars).
,
Y
(
PARSLET_Y
ear
)
//
,
I
(
PARSLET_Y
ear
)
//
,
Q
(
PARSLET_M
onth
)
// Quarter of year (1, 2, 3, 4; JAN-MAR = 1).
,
DDD
(
PARSLET_D
AY
)
// Day of year (1-366).
,
DAY
(
PARSLET_D
AY
)
// Name of day.
,
DD
(
PARSLET_D
AY
)
// Day of month (1-31).
,
DY
(
PARSLET_D
AY
)
// Abbreviated name of day.
,
HH24
(
PARSLET_T
IME
)
//
,
HH12
(
PARSLET_T
IME
)
//
,
HH
(
PARSLET_T
IME
)
// Hour of day (1-12).
,
MI
(
PARSLET_T
IME
)
// Min
,
SSSSS
(
PARSLET_T
IME
)
// Seconds past midnight (0-86399)
,
SS
(
PARSLET_T
IME
)
//
,
FF
(
PARSLET_T
IME
,
PATTERN_FF
)
// Fractional seconds
,
TZH
(
PARSLET_T
IME
)
// Time zone hour.
,
TZM
(
PARSLET_T
IME
)
// Time zone minute.
,
TZR
(
PARSLET_T
IME
)
// Time zone region ID
,
TZD
(
PARSLET_T
IME
)
// Daylight savings information. Example: PST (for US/Pacific standard time);
,
AM_PM
(
PARSLET_T
IME
,
PATTERN_AM_PM
)
// Meridian indicator
,
EE
(
PARSLET_Y
EAR
)
// NOT supported yet - Full era name (Japanese Imperial, ROC Official, and Thai Buddha calendars).
,
E
(
PARSLET_Y
EAR
)
// NOT supported yet - Abbreviated era name (Japanese Imperial, ROC Official, and Thai Buddha calendars).
,
Y
(
PARSLET_Y
EAR
)
//
,
I
(
PARSLET_Y
EAR
)
//
,
Q
(
PARSLET_M
ONTH
)
// Quarter of year (1, 2, 3, 4; JAN-MAR = 1).
//, W(PARSLET_Week) // Week of month (1-5)
,
D
(
PARSLET_D
ay
)
// Day of week (1-7).
,
J
(
PARSLET_D
ay
);
// NOT supported yet - Julian day; the number of days since Jan 1, 4712 BC.
,
D
(
PARSLET_D
AY
)
// Day of week (1-7).
,
J
(
PARSLET_D
AY
);
// NOT supported yet - Julian day; the number of days since Jan 1, 4712 BC.
private
final
static
Map
<
Character
,
List
<
FormatTokenEnum
>>
cache
=
new
HashMap
<
Character
,
List
<
FormatTokenEnum
>>(
FormatTokenEnum
.
values
().
length
);
...
...
@@ -176,20 +176,20 @@ class ToDateTokenizer {
case
SYYYY:
case
YYYY:
case
IYYY:
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
4_Digit
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
FOUR_DIGITS
,
params
,
formatTokenEnum
);
dateNr
=
parseInt
(
inputFragmentStr
);
// Gregorian calendar does not have a year 0. 0 = 0001 BC, -1 = 0002 BC, ... so we adjust
result
.
set
(
Calendar
.
YEAR
,
dateNr
>=
0
?
dateNr
:
dateNr
+
1
);
break
;
case
YYY:
case
IYY:
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
3_Digit
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
THREE_DIGITS
,
params
,
formatTokenEnum
);
dateNr
=
parseInt
(
inputFragmentStr
);
// Gregorian calendar does not have a year 0. 0 = 0001 BC, -1 = 0002 BC, ... so we adjust
result
.
set
(
Calendar
.
YEAR
,
dateNr
>=
0
?
dateNr
:
dateNr
+
1
);
break
;
case
RRRR:
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
2_Digit
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
TWO_DIGITS
,
params
,
formatTokenEnum
);
dateNr
=
parseInt
(
inputFragmentStr
);
dateNr
+=
dateNr
<
50
?
2000
:
1900
;
result
.
set
(
Calendar
.
YEAR
,
dateNr
);
...
...
@@ -197,7 +197,7 @@ class ToDateTokenizer {
case
RR:
Calendar
calendar
=
Calendar
.
getInstance
();
int
cc
=
(
calendar
.
get
(
Calendar
.
YEAR
)
/
100
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
2_Digit
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
TWO_DIGITS
,
params
,
formatTokenEnum
);
dateNr
=
parseInt
(
inputFragmentStr
)
+
cc
*
100
;
result
.
set
(
Calendar
.
YEAR
,
dateNr
);
break
;
...
...
@@ -209,20 +209,20 @@ class ToDateTokenizer {
break
;
case
YY:
case
IY:
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
2_Digit
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
TWO_DIGITS
,
params
,
formatTokenEnum
);
dateNr
=
parseInt
(
inputFragmentStr
);
// Gregorian calendar does not have a year 0. 0 = 0001 BC, -1 = 0002 BC, ... so we adjust
result
.
set
(
Calendar
.
YEAR
,
dateNr
>=
0
?
dateNr
:
dateNr
+
1
);
break
;
case
SCC:
case
CC:
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
2_Digit
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
TWO_DIGITS
,
params
,
formatTokenEnum
);
dateNr
=
parseInt
(
inputFragmentStr
)
*
100
;
result
.
set
(
Calendar
.
YEAR
,
dateNr
);
break
;
case
Y:
case
I:
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
1_Digit
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
ONE_DIGIT
,
params
,
formatTokenEnum
);
dateNr
=
parseInt
(
inputFragmentStr
);
// Gregorian calendar does not have a year 0. 0 = 0001 BC, -1 = 0002 BC, ... so we adjust
result
.
set
(
Calendar
.
YEAR
,
dateNr
>=
0
?
dateNr
:
dateNr
+
1
);
...
...
@@ -271,7 +271,7 @@ class ToDateTokenizer {
break
;
case
MM:
// Note: In Calendar Month go from 0 - 11
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
2_DigitOrLess
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
TWO_DIGITS_OR_LESS
,
params
,
formatTokenEnum
);
dateNr
=
parseInt
(
inputFragmentStr
);
result
.
set
(
Calendar
.
MONTH
,
dateNr
-
1
);
break
;
...
...
@@ -313,14 +313,14 @@ class ToDateTokenizer {
int dateNr = 0;
switch (formatTokenEnum) {
case WW:
inputFragmentStr = matchStringOrDie(PATTERN_
2_DigitOrLess
, params, formatTokenEnum);
inputFragmentStr = matchStringOrDie(PATTERN_
TWO_DIGITS_OR_LESS
, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr);
// The first week of the month, as defined by
// getFirstDayOfWeek() and getMinimalDaysInFirstWeek(),
result.set(Calendar.WEEK_OF_YEAR, dateNr);
break;
case IW:
inputFragmentStr = matchStringOrDie(PATTERN_
2_DigitOrLess
, params, formatTokenEnum);
inputFragmentStr = matchStringOrDie(PATTERN_
TWO_DIGITS_OR_LESS
, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr);
// Build set the calendar to ISO8601 (see
// http://en.wikipedia.org/wiki/ISO_8601_week_number)
...
...
@@ -329,7 +329,7 @@ class ToDateTokenizer {
result.set(Calendar.WEEK_OF_YEAR, dateNr);
break;
case W:
inputFragmentStr = matchStringOrDie(PATTERN_
1_Digit
, params, formatTokenEnum);
inputFragmentStr = matchStringOrDie(PATTERN_
ONE_DIGIT
, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr);
// The first week of the month, as defined by
// getFirstDayOfWeek() and getMinimalDaysInFirstWeek(),
...
...
@@ -357,17 +357,17 @@ class ToDateTokenizer {
int
dateNr
=
0
;
switch
(
formatTokenEnum
)
{
case
DDD:
inputFragmentStr
=
matchStringOrDie
(
PATTERN_N
umber
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_N
UMBER
,
params
,
formatTokenEnum
);
dateNr
=
parseInt
(
inputFragmentStr
);
result
.
set
(
Calendar
.
DAY_OF_YEAR
,
dateNr
);
break
;
case
DD:
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
2_DigitOrLess
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
TWO_DIGITS_OR_LESS
,
params
,
formatTokenEnum
);
dateNr
=
parseInt
(
inputFragmentStr
);
result
.
set
(
Calendar
.
DAY_OF_MONTH
,
dateNr
);
break
;
case
D:
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
1_Digit
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
ONE_DIGIT
,
params
,
formatTokenEnum
);
dateNr
=
parseInt
(
inputFragmentStr
);
result
.
set
(
Calendar
.
DAY_OF_MONTH
,
dateNr
);
break
;
...
...
@@ -378,7 +378,7 @@ class ToDateTokenizer {
inputFragmentStr
=
setByName
(
result
,
params
,
Calendar
.
DAY_OF_WEEK
,
Calendar
.
SHORT
);
break
;
case
J:
inputFragmentStr
=
matchStringOrDie
(
PATTERN_N
umber
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_N
UMBER
,
params
,
formatTokenEnum
);
try
{
Date
date
=
new
SimpleDateFormat
(
"Myydd"
).
parse
(
inputFragmentStr
);
result
.
setTime
(
date
);
...
...
@@ -410,35 +410,35 @@ class ToDateTokenizer {
int
dateNr
=
0
;
switch
(
formatTokenEnum
)
{
case
HH24:
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
2_DigitOrLess
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
TWO_DIGITS_OR_LESS
,
params
,
formatTokenEnum
);
dateNr
=
parseInt
(
inputFragmentStr
);
result
.
set
(
Calendar
.
HOUR_OF_DAY
,
dateNr
);
break
;
case
HH12:
case
HH:
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
2_DigitOrLess
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
TWO_DIGITS_OR_LESS
,
params
,
formatTokenEnum
);
dateNr
=
parseInt
(
inputFragmentStr
);
result
.
set
(
Calendar
.
HOUR
,
dateNr
);
break
;
case
MI:
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
2_DigitOrLess
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
TWO_DIGITS_OR_LESS
,
params
,
formatTokenEnum
);
dateNr
=
parseInt
(
inputFragmentStr
);
result
.
set
(
Calendar
.
MINUTE
,
dateNr
);
break
;
case
SS:
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
2_DigitOrLess
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
TWO_DIGITS_OR_LESS
,
params
,
formatTokenEnum
);
dateNr
=
parseInt
(
inputFragmentStr
);
result
.
set
(
Calendar
.
SECOND
,
dateNr
);
break
;
case
SSSSS:
inputFragmentStr
=
matchStringOrDie
(
PATTERN_N
umber
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_N
UMBER
,
params
,
formatTokenEnum
);
dateNr
=
parseInt
(
inputFragmentStr
);
result
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
result
.
set
(
Calendar
.
MINUTE
,
0
);
result
.
set
(
Calendar
.
SECOND
,
dateNr
);
break
;
case
FF:
//
inputFragmentStr
=
matchStringOrDie
(
PATTERN_N
umber
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_N
UMBER
,
params
,
formatTokenEnum
);
String
paddedRightNrStr
=
format
(
"%-9s"
,
inputFragmentStr
).
replace
(
' '
,
'0'
);
paddedRightNrStr
=
paddedRightNrStr
.
substring
(
0
,
9
);
Double
nineDigits
=
Double
.
parseDouble
(
paddedRightNrStr
);
...
...
@@ -457,7 +457,7 @@ class ToDateTokenizer {
break
;
case
TZH:
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
2_DigitOrLess
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
TWO_DIGITS_OR_LESS
,
params
,
formatTokenEnum
);
dateNr
=
parseInt
(
inputFragmentStr
);
TimeZone
tz
=
result
.
getTimeZone
();
int
offsetMillis
=
tz
.
getRawOffset
();
...
...
@@ -466,7 +466,7 @@ class ToDateTokenizer {
result
.
setTimeZone
(
tz
);
break
;
case
TZM:
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
2_DigitOrLess
,
params
,
formatTokenEnum
);
inputFragmentStr
=
matchStringOrDie
(
PATTERN_
TWO_DIGITS_OR_LESS
,
params
,
formatTokenEnum
);
dateNr
=
parseInt
(
inputFragmentStr
);
tz
=
result
.
getTimeZone
();
offsetMillis
=
tz
.
getRawOffset
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论