Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace UtcOffset with java.time.ZoneOffset
- Loading branch information
1 parent
5de0275
commit 7d18cb0
Showing
9 changed files
with
233 additions
and
171 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
39 changes: 39 additions & 0 deletions
39
src/main/java/net/fortuna/ical4j/model/ZoneOffsetAdapter.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,39 @@ | ||
package net.fortuna.ical4j.model; | ||
|
||
import java.io.Serializable; | ||
import java.time.ZoneOffset; | ||
|
||
/** | ||
* Support adapter for {@link java.time.ZoneOffset} to output in iCalendar format. | ||
*/ | ||
public class ZoneOffsetAdapter implements Serializable { | ||
|
||
private final ZoneOffset offset; | ||
|
||
public ZoneOffsetAdapter(ZoneOffset offset) { | ||
this.offset = offset; | ||
} | ||
|
||
public ZoneOffset getOffset() { | ||
return offset; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String retVal = ""; | ||
if (offset != null) { | ||
int hours = Math.abs(offset.getTotalSeconds()) / (60 * 60); | ||
if (offset.getTotalSeconds() < 0) { | ||
hours = -hours; | ||
} | ||
int minutes = Math.abs(offset.getTotalSeconds()) % (60 * 60) / 60; | ||
int seconds = Math.abs(offset.getTotalSeconds()) % (60 * 60) % 60; | ||
if (seconds > 0) { | ||
retVal = String.format("%+03d%02d%02d", hours, minutes, seconds); | ||
} else { | ||
retVal = String.format("%+03d%02d", hours, minutes); | ||
} | ||
} | ||
return retVal; | ||
} | ||
} |
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.