Created
March 3, 2019 14:44
-
-
Save orekyuu/ada1445e983132512cfeb18c3f53f0f8 to your computer and use it in GitHub Desktop.
いい感じに時間を扱いたい
This file contains hidden or 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
package net.orekyuu.bitemporaldomaexample.domain.type; | |
/** | |
* システム的な変更時のシステム時間の変化 | |
*/ | |
public class TerminatedTransactionTime { | |
private final TransactionTime newTransaction; | |
private final TransactionTime terminatedTransaction; | |
TerminatedTransactionTime(TransactionTime newTransaction, TransactionTime terminatedTransaction) { | |
this.newTransaction = newTransaction; | |
this.terminatedTransaction = terminatedTransaction; | |
} | |
public TransactionTime newTransaction() { | |
return newTransaction; | |
} | |
public TransactionTime terminatedTransaction() { | |
return terminatedTransaction; | |
} | |
} |
This file contains hidden or 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
package net.orekyuu.bitemporaldomaexample.domain.type; | |
import org.seasar.doma.Column; | |
import org.seasar.doma.Embeddable; | |
import java.time.LocalDateTime; | |
/** | |
* システム的な有効時間 | |
*/ | |
@Embeddable | |
public class TransactionTime { | |
@Column | |
private final LocalDateTime processFrom; | |
@Column | |
private final LocalDateTime processThru; | |
static final LocalDateTime MAX = LocalDateTime.of(9999, 12, 31, 23, 59, 59); | |
TransactionTime(LocalDateTime processFrom, LocalDateTime processThru) { | |
this.processFrom = processFrom; | |
this.processThru = processThru; | |
} | |
public static TransactionTime create(LocalDateTime time) { | |
return new TransactionTime(time, LocalDateTime.MAX); | |
} | |
public TerminatedTransactionTime terminate(LocalDateTime time) { | |
return new TerminatedTransactionTime( | |
new TransactionTime(time, MAX), | |
new TransactionTime(processFrom, time)); | |
} | |
public LocalDateTime processFrom() { | |
return processFrom; | |
} | |
public LocalDateTime processThru() { | |
return processThru; | |
} | |
} |
This file contains hidden or 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
package net.orekyuu.bitemporaldomaexample.domain.type; | |
import org.seasar.doma.Column; | |
import org.seasar.doma.Embeddable; | |
import java.time.LocalDateTime; | |
/** | |
* ビジネス的な有効時間 | |
*/ | |
@Embeddable | |
public class ValidTime { | |
@Column | |
private final LocalDateTime businessIn; | |
@Column | |
private final LocalDateTime businessOut; | |
private static final LocalDateTime MAX = LocalDateTime.of(9999, 12, 31, 23, 59, 59); | |
ValidTime(LocalDateTime businessIn, LocalDateTime businessOut) { | |
this.businessIn = businessIn; | |
this.businessOut = businessOut; | |
} | |
public static ValidTime create(LocalDateTime in, LocalDateTime out) { | |
return new ValidTime(in, out); | |
} | |
public static ValidTime createInfinity(LocalDateTime in) { | |
return create(in, LocalDateTime.MAX); | |
} | |
public ValidTime terminate(LocalDateTime time) { | |
return new ValidTime(businessIn, time); | |
} | |
public LocalDateTime businessIn() { | |
return businessIn; | |
} | |
public LocalDateTime businessOut() { | |
return businessOut; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment