-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor DateTimeFormatterFactory (#29205)
- Loading branch information
Showing
19 changed files
with
186 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...src/main/java/org/apache/shardingsphere/infra/util/datetime/DateTimeFormatterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.infra.util.datetime; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.format.DateTimeFormatter; | ||
|
||
/** | ||
* Date time formatter factory. | ||
*/ | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class DateTimeFormatterFactory { | ||
|
||
private static final DateTimeFormatter STANDARD = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
|
||
private static final DateTimeFormatter DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | ||
|
||
private static final DateTimeFormatter TIME = DateTimeFormatter.ofPattern("HH:mm:ss"); | ||
|
||
private static final DateTimeFormatter SHORT_MILLS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S"); | ||
|
||
private static final DateTimeFormatter LONG_MILLS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); | ||
|
||
/** | ||
* Get standard date time formatter. | ||
* | ||
* @return standard date time formatter | ||
*/ | ||
public static DateTimeFormatter getStandardFormatter() { | ||
return STANDARD; | ||
} | ||
|
||
/** | ||
* Get date formatter. | ||
* | ||
* @return date formatter | ||
*/ | ||
public static DateTimeFormatter getDateFormatter() { | ||
return DATE; | ||
} | ||
|
||
/** | ||
* Get time formatter. | ||
* | ||
* @return time formatter | ||
*/ | ||
public static DateTimeFormatter getTimeFormatter() { | ||
return TIME; | ||
} | ||
|
||
/** | ||
* Get short mills date time formatter. | ||
* | ||
* @return short mills date time formatter | ||
*/ | ||
public static DateTimeFormatter getShortMillsFormatter() { | ||
return SHORT_MILLS; | ||
} | ||
|
||
/** | ||
* Get long mills date time formatter. | ||
* | ||
* @return long mills date time formatter | ||
*/ | ||
public static DateTimeFormatter getLongMillsFormatter() { | ||
return LONG_MILLS; | ||
} | ||
} |
41 changes: 0 additions & 41 deletions
41
...rc/main/java/org/apache/shardingsphere/infra/util/datetime/StandardDateTimeFormatter.java
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
...test/java/org/apache/shardingsphere/infra/util/datetime/DateTimeFormatterFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.infra.util.datetime; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
class DateTimeFormatterFactoryTest { | ||
|
||
@Test | ||
void assertGetStandardFormatter() { | ||
assertThat(DateTimeFormatterFactory.getStandardFormatter().parse("1970-01-01 00:00:00").toString(), is("{},ISO resolved to 1970-01-01T00:00")); | ||
} | ||
|
||
@Test | ||
void assertGetDateFormatter() { | ||
assertThat(DateTimeFormatterFactory.getDateFormatter().parse("1970-01-01").toString(), is("{},ISO resolved to 1970-01-01")); | ||
} | ||
|
||
@Test | ||
void assertGetTimeFormatter() { | ||
assertThat(DateTimeFormatterFactory.getTimeFormatter().parse("00:00:00").toString(), is("{},ISO resolved to 00:00")); | ||
} | ||
|
||
@Test | ||
void assertGetShortMillsFormatter() { | ||
assertThat(DateTimeFormatterFactory.getShortMillsFormatter().parse("1970-01-01 00:00:00.0").toString(), is("{},ISO resolved to 1970-01-01T00:00")); | ||
} | ||
|
||
@Test | ||
void assertGetLongMillsFormatter() { | ||
assertThat(DateTimeFormatterFactory.getLongMillsFormatter().parse("1970-01-01 00:00:00.000").toString(), is("{},ISO resolved to 1970-01-01T00:00")); | ||
} | ||
} |
31 changes: 0 additions & 31 deletions
31
...est/java/org/apache/shardingsphere/infra/util/datetime/StandardDateTimeFormatterTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.