docs: 修改注释和文档

This commit is contained in:
zhouxy108 2025-03-22 15:36:17 +08:00
parent 2f1df1b188
commit e989ad8f60
2 changed files with 71 additions and 4 deletions

View File

@ -44,7 +44,9 @@ import xyz.zhouxy.plusone.commons.time.YearQuarter;
*/ */
public class DateTimeTools { public class DateTimeTools {
// ================================
// #region - toString // #region - toString
// ================================
public static String toYearString(int year) { public static String toYearString(int year) {
return Integer.toString(YEAR.checkValidIntValue(year)); return Integer.toString(YEAR.checkValidIntValue(year));
@ -70,9 +72,13 @@ public class DateTimeTools {
return String.format("%02d", month.getValue()); return String.format("%02d", month.getValue());
} }
// ================================
// #endregion // #endregion
// ================================
// ================================
// #region - toDate // #region - toDate
// ================================
/** /**
* 将时间戳转换为 {@link Date} 对象 * 将时间戳转换为 {@link Date} 对象
@ -137,9 +143,13 @@ public class DateTimeTools {
return Date.from(ZonedDateTime.of(localDate, localTime, zone).toInstant()); return Date.from(ZonedDateTime.of(localDate, localTime, zone).toInstant());
} }
// ================================
// #endregion // #endregion
// ================================
// ================================
// #region - toInstant // #region - toInstant
// ================================
/** /**
* 将时间戳转换为 {@link Instant} 对象 * 将时间戳转换为 {@link Instant} 对象
@ -192,9 +202,13 @@ public class DateTimeTools {
return ZonedDateTime.of(localDateTime, zone).toInstant(); return ZonedDateTime.of(localDateTime, zone).toInstant();
} }
// ================================
// #endregion // #endregion
// ================================
// ================================
// #region - toZonedDateTime // #region - toZonedDateTime
// ================================
/** /**
* 获取时间戳在指定时区的地区时间 * 获取时间戳在指定时区的地区时间
@ -285,9 +299,13 @@ public class DateTimeTools {
return ZonedDateTime.of(localDateTime, zone); return ZonedDateTime.of(localDateTime, zone);
} }
// ================================
// #endregion // #endregion
// ================================
// ================================
// #region - toLocalDateTime // #region - toLocalDateTime
// ================================
/** /**
* 获取时间戳在指定时区的地区时间 * 获取时间戳在指定时区的地区时间
@ -355,11 +373,13 @@ public class DateTimeTools {
return LocalDateTime.ofInstant(zonedDateTime.toInstant(), zone); return LocalDateTime.ofInstant(zonedDateTime.toInstant(), zone);
} }
// ================================
// #endregion // #endregion
// ================================
// ==================== // ================================
// #region - toJodaInstant // #region - toJodaInstant
// ================================
/** /**
* {@link java.time.Instant} 转换为 {@link org.joda.time.Instant} * {@link java.time.Instant} 转换为 {@link org.joda.time.Instant}
@ -392,9 +412,13 @@ public class DateTimeTools {
return toJodaInstant(java.time.ZonedDateTime.of(localDateTime, zone)); return toJodaInstant(java.time.ZonedDateTime.of(localDateTime, zone));
} }
// ================================
// #endregion // #endregion
// ================================
// ================================
// #region - toJavaInstant // #region - toJavaInstant
// ================================
/** /**
* {@link org.joda.time.Instant} 对象转换为 {@link java.time.Instant} 对象 * {@link org.joda.time.Instant} 对象转换为 {@link java.time.Instant} 对象
@ -432,9 +456,13 @@ public class DateTimeTools {
return toJavaInstant(localDateTime.toDateTime(zone)); return toJavaInstant(localDateTime.toDateTime(zone));
} }
// ================================
// #endregion // #endregion
// ================================
// ================================
// #region - toJodaDateTime // #region - toJodaDateTime
// ================================
/** /**
* Java 中表示日期时间的 {@link java.time.ZonedDateTime} 对象 * Java 中表示日期时间的 {@link java.time.ZonedDateTime} 对象
@ -479,9 +507,13 @@ public class DateTimeTools {
return toJodaInstant(instant).toDateTime(dateTimeZone); return toJodaInstant(instant).toDateTime(dateTimeZone);
} }
// ================================
// #endregion // #endregion
// ================================
// ================================
// #region - toZonedDateTime // #region - toZonedDateTime
// ================================
/** /**
* joda-time 中带时区的日期时间转换为 java.time 中带时区的日期时间 * joda-time 中带时区的日期时间转换为 java.time 中带时区的日期时间
@ -511,7 +543,7 @@ public class DateTimeTools {
} }
/** /**
* 获取 joda-time 中的 {@link org.joda.time.Instant} 在指定时区的时间 Java 8 * 获取 joda-time 中的 {@link org.joda.time.Instant} 在指定时区的时间 Java 8+
* {@link java.time.ZonedDateTime} 表示 * {@link java.time.ZonedDateTime} 表示
* *
* @param instant joda-time 中的时间戳 * @param instant joda-time 中的时间戳
@ -525,9 +557,13 @@ public class DateTimeTools {
return toJavaInstant(instant).atZone(zone); return toJavaInstant(instant).atZone(zone);
} }
// ================================
// #endregion // #endregion
// ================================
// ================================
// #region - toJodaLocalDateTime // #region - toJodaLocalDateTime
// ================================
/** /**
* {@link java.time.LocalDateTime} 转换为 {@link org.joda.time.LocalDateTime} * {@link java.time.LocalDateTime} 转换为 {@link org.joda.time.LocalDateTime}
@ -541,9 +577,13 @@ public class DateTimeTools {
return toJodaInstant(localDateTime, javaZone).toDateTime(jodaZone).toLocalDateTime(); return toJodaInstant(localDateTime, javaZone).toDateTime(jodaZone).toLocalDateTime();
} }
// ================================
// #endregion // #endregion
// ================================
// ================================
// #region - toJavaLocalDateTime // #region - toJavaLocalDateTime
// ================================
/** /**
* {@link org.joda.time.LocalDateTime} 转换为 {@link java.time.LocalDateTime} * {@link org.joda.time.LocalDateTime} 转换为 {@link java.time.LocalDateTime}
@ -557,9 +597,13 @@ public class DateTimeTools {
return toJavaInstant(localDateTime, jodaZone).atZone(javaZone).toLocalDateTime(); return toJavaInstant(localDateTime, jodaZone).atZone(javaZone).toLocalDateTime();
} }
// ================================
// #endregion // #endregion
// ================================
// ================================
// #region - ZoneId <--> DateTimeZone // #region - ZoneId <--> DateTimeZone
// ================================
/** /**
* 转换 Java API joda-time API 表示时区的对象 * 转换 Java API joda-time API 表示时区的对象
@ -581,9 +625,13 @@ public class DateTimeTools {
return org.joda.time.DateTimeZone.forID(zone.getId()); return org.joda.time.DateTimeZone.forID(zone.getId());
} }
// ================================
// #endregion // #endregion
// ================================
// ================================
// #region - YearQuarter & Quarter // #region - YearQuarter & Quarter
// ================================
/** /**
* 获取指定日期所在季度 * 获取指定日期所在季度
@ -646,10 +694,12 @@ public class DateTimeTools {
return YearQuarter.of(date); return YearQuarter.of(date);
} }
// ================================
// #endregion // #endregion
// ================================
// ================================ // ================================
// #region - others // #region - start & end
// ================================ // ================================
public static LocalDate startDateOfYear(int year) { public static LocalDate startDateOfYear(int year) {
@ -668,6 +718,14 @@ public class DateTimeTools {
return date.plusDays(1L).atStartOfDay(zone); return date.plusDays(1L).atStartOfDay(zone);
} }
// ================================
// #endregion - start & end
// ================================
// ================================
// #region - others
// ================================
public static Range<LocalDateTime> toDateTimeRange(LocalDate date) { public static Range<LocalDateTime> toDateTimeRange(LocalDate date) {
return Range.closedOpen(date.atStartOfDay(), startOfNextDate(date)); return Range.closedOpen(date.atStartOfDay(), startOfNextDate(date));
} }

View File

@ -20,6 +20,15 @@ import java.util.Objects;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/**
* StringTools
*
* <p>
* 字符串工具类
* </p>
*
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
*/
public class StringTools { public class StringTools {
public static final String EMPTY_STRING = ""; public static final String EMPTY_STRING = "";