45 lines
1.3 KiB
Java
45 lines
1.3 KiB
Java
package io.gitlab.jfronny.muscript.data.dynamic.additional;
|
|
|
|
import io.gitlab.jfronny.muscript.compiler.ExprWriter;
|
|
import io.gitlab.jfronny.muscript.data.dynamic.*;
|
|
|
|
import java.io.IOException;
|
|
import java.time.LocalTime;
|
|
import java.util.Map;
|
|
import java.util.function.Supplier;
|
|
|
|
public record DTime(Supplier<LocalTime> time) implements DObject {
|
|
@Override
|
|
public Map<String, Dynamic<?>> getValue() {
|
|
return Map.of(
|
|
"hour", DFinal.of(time.get().getHour()),
|
|
"minute", DFinal.of(time.get().getMinute()),
|
|
"second", DFinal.of(time.get().getSecond())
|
|
);
|
|
}
|
|
|
|
@Override
|
|
public DString asString() {
|
|
return DFinal.of(toString());
|
|
}
|
|
|
|
@Override
|
|
public DNumber asNumber() {
|
|
return DFinal.of(time.get().toSecondOfDay());
|
|
}
|
|
|
|
@Override
|
|
public void serialize(ExprWriter writer) throws IOException {
|
|
writer.append("time(")
|
|
.append(String.valueOf(time.get().getHour())).append(", ")
|
|
.append(String.valueOf(time.get().getMinute())).append(", ")
|
|
.append(String.valueOf(time.get().getSecond()))
|
|
.append(")");
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return time.get().toString();
|
|
}
|
|
}
|