generated from Fallen-Breath/fabric-mod-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
31 changed files
with
1,322 additions
and
30 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
107 changes: 107 additions & 0 deletions
107
src/main/java/com/sakuraryoko/corelib/api/time/DurationFormat.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,107 @@ | ||
/* | ||
* This file is part of the CoreLib project, licensed under the | ||
* GNU Lesser General Public License v3.0 | ||
* | ||
* Copyright (C) 2024 Sakura Ryoko and contributors | ||
* | ||
* CoreLib is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* CoreLib 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 Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with CoreLib. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.sakuraryoko.corelib.api.time; | ||
|
||
import javax.annotation.Nullable; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
import com.sakuraryoko.corelib.impl.time.DurationFmtType; | ||
import com.sakuraryoko.corelib.impl.time.formatter.DurationFmt; | ||
|
||
public enum DurationFormat | ||
{ | ||
REGULAR ("regular", DurationFmtType.REGULAR), | ||
PRETTY ("pretty", DurationFmtType.PRETTY), | ||
ISO_EXTENDED ("iso_extended", DurationFmtType.ISO_EXTENDED), | ||
FORMATTED ("formatted", DurationFmtType.FORMATTED); | ||
|
||
public static final ImmutableList<DurationFormat> VALUES = ImmutableList.copyOf(values()); | ||
|
||
final String name; | ||
final DurationFmtType<?> type; | ||
|
||
DurationFormat(String name, DurationFmtType<?> type) | ||
{ | ||
this.name = name; | ||
this.type = type; | ||
} | ||
|
||
public String getName() { return this.name; } | ||
|
||
public DurationFmtType<?> getType() | ||
{ | ||
return this.type; | ||
} | ||
|
||
public @Nullable DurationFmt init() | ||
{ | ||
return this.type.init(this); | ||
} | ||
|
||
public String getFormat(long duration, @Nullable String fmt) | ||
{ | ||
DurationFmt formatter = this.init(); | ||
|
||
if (formatter != null) | ||
{ | ||
if (duration < 1) | ||
{ | ||
return "Invalid Duration ["+duration+"]"; | ||
} | ||
|
||
return formatter.format(duration, fmt); | ||
} | ||
|
||
return ""; | ||
} | ||
|
||
public String getFormatString() | ||
{ | ||
DurationFmt formatter = this.init(); | ||
|
||
if (formatter != null) | ||
{ | ||
return formatter.getFormatString(); | ||
} | ||
|
||
return ""; | ||
} | ||
|
||
@Nullable | ||
public static DurationFormat fromName(String name) | ||
{ | ||
for (DurationFormat val : VALUES) | ||
{ | ||
if (name.compareToIgnoreCase(val.getName()) == 0) | ||
{ | ||
return val; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return this.getName(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/sakuraryoko/corelib/api/time/DurationOption.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,52 @@ | ||
/* | ||
* This file is part of the CoreLib project, licensed under the | ||
* GNU Lesser General Public License v3.0 | ||
* | ||
* Copyright (C) 2024 Sakura Ryoko and contributors | ||
* | ||
* CoreLib is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* CoreLib 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 Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with CoreLib. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.sakuraryoko.corelib.api.time; | ||
|
||
import com.sakuraryoko.corelib.api.config.IConfigOption; | ||
|
||
public class DurationOption implements IConfigOption | ||
{ | ||
public DurationFormat option; | ||
public String customFormat; | ||
|
||
public DurationOption() | ||
{ | ||
this.defaults(); | ||
} | ||
|
||
@Override | ||
public void defaults() | ||
{ | ||
this.option = DurationFormat.REGULAR; | ||
this.customFormat = ""; | ||
} | ||
|
||
@Override | ||
public DurationOption copy(IConfigOption opt) | ||
{ | ||
DurationOption opts = (DurationOption) opt; | ||
|
||
this.option = opts.option; | ||
this.customFormat = opts.customFormat; | ||
|
||
return this; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/sakuraryoko/corelib/api/time/TimeDateOption.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,52 @@ | ||
/* | ||
* This file is part of the CoreLib project, licensed under the | ||
* GNU Lesser General Public License v3.0 | ||
* | ||
* Copyright (C) 2024 Sakura Ryoko and contributors | ||
* | ||
* CoreLib is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* CoreLib 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 Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with CoreLib. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.sakuraryoko.corelib.api.time; | ||
|
||
import com.sakuraryoko.corelib.api.config.IConfigOption; | ||
|
||
public class TimeDateOption implements IConfigOption | ||
{ | ||
public TimeFormat option; | ||
public String customFormat; | ||
|
||
public TimeDateOption() | ||
{ | ||
this.defaults(); | ||
} | ||
|
||
@Override | ||
public void defaults() | ||
{ | ||
this.option = TimeFormat.REGULAR; | ||
this.customFormat = ""; | ||
} | ||
|
||
@Override | ||
public TimeDateOption copy(IConfigOption opt) | ||
{ | ||
TimeDateOption opts = (TimeDateOption) opt; | ||
|
||
this.option = opts.option; | ||
this.customFormat = opts.customFormat; | ||
|
||
return this; | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
src/main/java/com/sakuraryoko/corelib/api/time/TimeFormat.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,128 @@ | ||
/* | ||
* This file is part of the CoreLib project, licensed under the | ||
* GNU Lesser General Public License v3.0 | ||
* | ||
* Copyright (C) 2024 Sakura Ryoko and contributors | ||
* | ||
* CoreLib is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* CoreLib 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 Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with CoreLib. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.sakuraryoko.corelib.api.time; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import com.google.common.collect.ImmutableList; | ||
|
||
import com.sakuraryoko.corelib.impl.time.TimeFmtType; | ||
import com.sakuraryoko.corelib.impl.time.formatter.TimeFmt; | ||
|
||
public enum TimeFormat | ||
{ | ||
REGULAR ("regular", TimeFmtType.REGULAR), | ||
ISO_LOCAL ("iso_local", TimeFmtType.ISO_LOCAL), | ||
ISO_OFFSET ("iso_offset", TimeFmtType.ISO_OFFSET), | ||
FORMATTED ("formatted", TimeFmtType.FORMATTED), | ||
RFC1123 ("rfc1123", TimeFmtType.RFC1123); | ||
|
||
public static final ImmutableList<TimeFormat> VALUES = ImmutableList.copyOf(values()); | ||
|
||
final String name; | ||
final TimeFmtType<?> type; | ||
|
||
TimeFormat(String name, TimeFmtType<?> type) | ||
{ | ||
this.name = name; | ||
this.type = type; | ||
} | ||
|
||
public String getName() { return this.name; } | ||
|
||
public TimeFmtType<?> getType() | ||
{ | ||
return this.type; | ||
} | ||
|
||
public @Nullable TimeFmt init() | ||
{ | ||
return this.type.init(this); | ||
} | ||
|
||
public String formatTo(long time, @Nullable String fmt) | ||
{ | ||
TimeFmt formatter = this.init(); | ||
|
||
if (formatter != null) | ||
{ | ||
return formatter.formatTo(time, fmt); | ||
} | ||
|
||
return ""; | ||
} | ||
|
||
public long formatFrom(@Nonnull String formattedTime, @Nullable String fmt) | ||
{ | ||
TimeFmt formatter = this.init(); | ||
|
||
if (formatter != null) | ||
{ | ||
return formatter.formatFrom(formattedTime, fmt); | ||
} | ||
|
||
return 0L; | ||
} | ||
|
||
public String formatNow(@Nullable String fmt) | ||
{ | ||
TimeFmt formatter = this.init(); | ||
|
||
if (formatter != null) | ||
{ | ||
return formatter.formatNow(fmt); | ||
} | ||
|
||
return ""; | ||
} | ||
|
||
public String getFormatString() | ||
{ | ||
TimeFmt formatter = this.init(); | ||
|
||
if (formatter != null) | ||
{ | ||
return formatter.getFormatString(); | ||
} | ||
|
||
return ""; | ||
} | ||
|
||
@Nullable | ||
public static TimeFormat fromName(String name) | ||
{ | ||
for (TimeFormat val : VALUES) | ||
{ | ||
if (name.compareToIgnoreCase(val.getName()) == 0) | ||
{ | ||
return val; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return this.getName(); | ||
} | ||
} |
Oops, something went wrong.