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
Showing
7 changed files
with
174 additions
and
4 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
34 changes: 34 additions & 0 deletions
34
src/main/java/eu/enhan/timelord/domain/util/DateTimeToStringConverter.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,34 @@ | ||
/* | ||
* This file is part of Timelord. | ||
* | ||
* Timelord is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Timelord is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the Affero GNU General Public License | ||
* along with Timemord. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package eu.enhan.timelord.domain.util; | ||
|
||
import org.joda.time.DateTime; | ||
import org.springframework.core.convert.converter.Converter; | ||
|
||
/** | ||
* @author Emmanuel Nhan | ||
* | ||
*/ | ||
public class DateTimeToStringConverter implements Converter<DateTime, String> { | ||
|
||
|
||
@Override | ||
public String convert(DateTime source) { | ||
return source.toString(); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/eu/enhan/timelord/domain/util/StringToDateTimeConverter.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,34 @@ | ||
/* | ||
* This file is part of Timelord. | ||
* | ||
* Timelord is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Timelord is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the Affero GNU General Public License | ||
* along with Timemord. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package eu.enhan.timelord.domain.util; | ||
|
||
import org.joda.time.DateTime; | ||
import org.springframework.core.convert.converter.Converter; | ||
|
||
/** | ||
* @author Emmanuel Nhan | ||
* | ||
*/ | ||
public class StringToDateTimeConverter implements Converter<String, DateTime> { | ||
|
||
@Override | ||
public DateTime convert(String source) { | ||
DateTime result = new DateTime(source); | ||
return result; | ||
} | ||
|
||
} |
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
53 changes: 53 additions & 0 deletions
53
src/test/java/eu/enhan/timelord/test/domain/util/DateTimeConversionTest.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,53 @@ | ||
/* | ||
* This file is part of Timelord. | ||
* | ||
* Timelord is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Timelord is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the Affero GNU General Public License | ||
* along with Timemord. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package eu.enhan.timelord.test.domain.util; | ||
|
||
import org.joda.time.DateTime; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import eu.enhan.timelord.domain.util.DateTimeToStringConverter; | ||
import eu.enhan.timelord.domain.util.StringToDateTimeConverter; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* @author Emmanuel Nhan | ||
* | ||
*/ | ||
public class DateTimeConversionTest { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(DateTimeConversionTest.class); | ||
|
||
@Test | ||
public void testConvertion(){ | ||
StringToDateTimeConverter stringToDate = new StringToDateTimeConverter(); | ||
DateTimeToStringConverter dateToString = new DateTimeToStringConverter(); | ||
|
||
DateTime time = new DateTime(2012, 2, 2, 10, 0); | ||
String converted = dateToString.convert(time); | ||
logger.debug("Converted value = {}.", converted); | ||
DateTime restored = stringToDate.convert(converted); | ||
|
||
assertEquals(time, restored); | ||
|
||
|
||
|
||
} | ||
|
||
} |