Skip to content

Commit

Permalink
feat: add LocalDateConverter and LocalDateTimeConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
r4tylmz committed Nov 14, 2024
1 parent 8a79422 commit 2620633
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.github.r4tylmz.betterpoi.converters;

import org.apache.commons.beanutils.Converter;

import java.time.LocalDate;

public class LocalDateConverter implements Converter {
@Override
public <T> T convert(Class<T> type, Object value) {
if (value == null) {
return null;
}

if (value instanceof LocalDate) {
return (T) value;
}
if (value instanceof java.util.Date) {
return (T) ((java.util.Date) value).toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate();
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.r4tylmz.betterpoi.converters;

import org.apache.commons.beanutils.Converter;

import java.time.LocalDateTime;

public class LocalDateTimeConverter implements Converter {
@Override
public <T> T convert(Class<T> type, Object value) {
if (value == null) {
return null;
}

if (value instanceof LocalDateTime) {
return (T) value;
}

if (value instanceof java.util.Date) {
return (T) ((java.util.Date) value).toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDateTime();
}
return null;
}
}

0 comments on commit 2620633

Please sign in to comment.