-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
badong2210
committed
Dec 20, 2012
1 parent
210c5ff
commit 8fa7954
Showing
16 changed files
with
552 additions
and
26 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,94 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
|
|||
<!-- | |||
~ Copyright (c) 2012. JSpringBot. All Rights Reserved. | |||
~ | |||
~ See the NOTICE file distributed with | |||
~ this work for additional information regarding copyright ownership. | |||
~ The JSpringBot 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. | |||
--> | |||
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" | |||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |||
|
|||
<modelVersion>4.0.0</modelVersion> | |||
|
|||
<parent> | |||
<groupId>org.jspringbot</groupId> | |||
<artifactId>jspringbot-libraries</artifactId> | |||
<version>1.0-SNAPSHOT</version> | |||
</parent> | |||
|
|||
<groupId>org.jspringbot</groupId> | |||
<artifactId>jspringbot-date</artifactId> | |||
<version>1.0-SNAPSHOT</version> | |||
|
|||
<packaging>jar</packaging> | |||
<name>jspringbot-date</name> | |||
|
|||
<build> | |||
<testResources> | |||
<testResource> | |||
<directory>src/test/resources</directory> | |||
<filtering>true</filtering> | |||
</testResource> | |||
</testResources> | |||
</build> | |||
|
|||
<properties> | |||
<libdoc.name>JSpringBot DB Library</libdoc.name> | |||
<libdoc.output>JSpringBotDBLibrary.html</libdoc.output> | |||
</properties> | |||
|
|||
<dependencies> | |||
<dependency> | |||
<groupId>commons-collections</groupId> | |||
<artifactId>commons-collections</artifactId> | |||
<version>3.2.1</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>commons-dbcp</groupId> | |||
<artifactId>commons-dbcp</artifactId> | |||
<version>1.4</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.jspringbot</groupId> | |||
<artifactId>jspringbot-syntax-highlight</artifactId> | |||
<version>${project.version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>junit</groupId> | |||
<artifactId>junit</artifactId> | |||
<version>${junit.version}</version> | |||
<optional>true</optional> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.mockito</groupId> | |||
<artifactId>mockito-all</artifactId> | |||
<version>1.8.0-rc2</version> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.springframework</groupId> | |||
<artifactId>spring-test</artifactId> | |||
<version>${spring.version}</version> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>joda-time</groupId> | |||
<artifactId>joda-time</artifactId> | |||
<version>2.1</version> | |||
</dependency> | |||
</dependencies> | |||
</project> |
30 changes: 30 additions & 0 deletions
30
jspringbot-date/src/main/java/org/jspringbot/keyword/date/AbstractDateKeyword.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
/* | |||
* Copyright (c) 2012. JSpringBot. All Rights Reserved. | |||
* | |||
* See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The JSpringBot 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.jspringbot.keyword.date; | |||
|
|||
import org.jspringbot.Keyword; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
|
|||
public abstract class AbstractDateKeyword implements Keyword { | |||
|
|||
@Autowired | |||
protected DateHelper helper; | |||
|
|||
public abstract Object execute(Object[] objects) throws Exception; | |||
} |
36 changes: 36 additions & 0 deletions
36
jspringbot-date/src/main/java/org/jspringbot/keyword/date/AddDateTimeDays.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
/* | |||
* Copyright (c) 2012. JSpringBot. All Rights Reserved. | |||
* | |||
* See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The JSpringBot 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.jspringbot.keyword.date; | |||
|
|||
import org.jspringbot.KeywordInfo; | |||
import org.springframework.stereotype.Component; | |||
|
|||
import java.io.IOException; | |||
|
|||
@Component | |||
@KeywordInfo(name = "Add Date Time Days", description = "Add the given days to the current date time.", parameters = {"numberOfDays"}) | |||
public class AddDateTimeDays extends AbstractDateKeyword { | |||
|
|||
@Override | |||
public Object execute(Object[] params) throws IOException { | |||
helper.plusDays(Integer.parseInt(String.valueOf(params[0]))); | |||
|
|||
return null; | |||
} | |||
} |
101 changes: 101 additions & 0 deletions
101
jspringbot-date/src/main/java/org/jspringbot/keyword/date/DateHelper.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,101 @@ | |||
/* | |||
* Copyright (c) 2012. JSpringBot. All Rights Reserved. | |||
* | |||
* See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The JSpringBot 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.jspringbot.keyword.date; | |||
|
|||
import org.joda.time.DateTime; | |||
import org.joda.time.DateTimeZone; | |||
import org.joda.time.format.DateTimeFormat; | |||
import org.joda.time.format.DateTimeFormatter; | |||
import org.jspringbot.syntax.HighlightRobotLogger; | |||
|
|||
public class DateHelper { | |||
public static final HighlightRobotLogger LOG = HighlightRobotLogger.getLogger(DateHelper.class); | |||
|
|||
private DateTime current = new DateTime(); | |||
|
|||
private DateTimeZone currentTimeZone = DateTimeZone.getDefault(); | |||
|
|||
private String formatterPattern = "yyyy-MM-dd HH:mm:ss zz"; | |||
|
|||
public void setDateTimeZone(String timeZoneId) { | |||
|
|||
LOG.createAppender() | |||
.appendBold("Set Date Time Zone:") | |||
.appendProperty("Time Zone ID", timeZoneId) | |||
.log(); | |||
|
|||
currentTimeZone = DateTimeZone.forID(timeZoneId); | |||
} | |||
|
|||
public void setDateTimeFormat(String pattern) { | |||
LOG.createAppender() | |||
.appendBold("Set Date Time Format:") | |||
.appendProperty("Pattern", pattern) | |||
.log(); | |||
|
|||
DateTimeFormat.forPattern(pattern); | |||
} | |||
|
|||
public String printDateTime() { | |||
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(formatterPattern); | |||
DateTime dt = current.withZone(currentTimeZone); | |||
|
|||
String formattedValue = dateTimeFormatter.print(dt); | |||
|
|||
LOG.createAppender() | |||
.appendBold("Print Date Time:") | |||
.appendProperty("Pattern", formatterPattern) | |||
.appendProperty("Time Zone ID", currentTimeZone.getID()) | |||
.appendProperty("Print", formattedValue) | |||
.log(); | |||
|
|||
return formattedValue; | |||
} | |||
|
|||
public void resetDateTime() { | |||
current = new DateTime(); | |||
|
|||
LOG.createAppender() | |||
.appendBold("Reset Date Time:") | |||
.appendProperty("Pattern", formatterPattern) | |||
.appendProperty("Time Zone ID", currentTimeZone.getID()) | |||
.appendProperty("Print", printDateTime()) | |||
.log(); | |||
} | |||
|
|||
public void plusDays(int days) { | |||
current = current.plusDays(days); | |||
|
|||
LOG.createAppender() | |||
.appendBold("Add Date Time Days:") | |||
.appendProperty("Days", days) | |||
.appendProperty("Print", printDateTime()) | |||
.log(); | |||
} | |||
|
|||
public void minusDays(int days) { | |||
current = current.minusDays(days); | |||
|
|||
LOG.createAppender() | |||
.appendBold("Subtract Date Time Days:") | |||
.appendProperty("Days", days) | |||
.appendProperty("Print", printDateTime()) | |||
.log(); | |||
} | |||
} |
34 changes: 34 additions & 0 deletions
34
jspringbot-date/src/main/java/org/jspringbot/keyword/date/PrintDateTime.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,34 @@ | |||
/* | |||
* Copyright (c) 2012. JSpringBot. All Rights Reserved. | |||
* | |||
* See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The JSpringBot 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.jspringbot.keyword.date; | |||
|
|||
import org.jspringbot.KeywordInfo; | |||
import org.springframework.stereotype.Component; | |||
|
|||
import java.io.IOException; | |||
|
|||
@Component | |||
@KeywordInfo(name = "Print Date Time", description = "Prints the date time to string given the set format.") | |||
public class PrintDateTime extends AbstractDateKeyword { | |||
|
|||
@Override | |||
public Object execute(Object[] params) throws IOException { | |||
return helper.printDateTime(); | |||
} | |||
} |
36 changes: 36 additions & 0 deletions
36
jspringbot-date/src/main/java/org/jspringbot/keyword/date/ResetDateTime.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
/* | |||
* Copyright (c) 2012. JSpringBot. All Rights Reserved. | |||
* | |||
* See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The JSpringBot 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.jspringbot.keyword.date; | |||
|
|||
import org.jspringbot.KeywordInfo; | |||
import org.springframework.stereotype.Component; | |||
|
|||
import java.io.IOException; | |||
|
|||
@Component | |||
@KeywordInfo(name = "Reset Date Time", description = "Reset date time to current date.") | |||
public class ResetDateTime extends AbstractDateKeyword { | |||
|
|||
@Override | |||
public Object execute(Object[] params) throws IOException { | |||
helper.resetDateTime(); | |||
|
|||
return null; | |||
} | |||
} |
36 changes: 36 additions & 0 deletions
36
jspringbot-date/src/main/java/org/jspringbot/keyword/date/SetDateTimeFormat.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
/* | |||
* Copyright (c) 2012. JSpringBot. All Rights Reserved. | |||
* | |||
* See the NOTICE file distributed with | |||
* this work for additional information regarding copyright ownership. | |||
* The JSpringBot 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.jspringbot.keyword.date; | |||
|
|||
import org.jspringbot.KeywordInfo; | |||
import org.springframework.stereotype.Component; | |||
|
|||
import java.io.IOException; | |||
|
|||
@Component | |||
@KeywordInfo(name = "Set Date Time Format", description = "Set the date time format pattern.", parameters = {"formatPattern"}) | |||
public class SetDateTimeFormat extends AbstractDateKeyword { | |||
|
|||
@Override | |||
public Object execute(Object[] params) throws IOException { | |||
helper.setDateTimeFormat(String.valueOf(params[0])); | |||
|
|||
return null; | |||
} | |||
} |
Oops, something went wrong.