object FakeTimer
Provides utility methods to fake current time of org.joda.time.DateTime.
Provided Methods
- fake
- fakeWithTimer
Basic Usage
import com.github.shibayu36.jodatimefake.FakeTimer import org.joda.time.DateTime // fake by millis val result = FakeTimer.fake(1515974400000L) { println(DateTime.now.toString) // 2018-01-15T00:00:00.000Z "hoge" } // current time is restored after block println(DateTime.now.toString) // current time is printed // You can get the value returned from block println(result) // hoge // You can also pass DateTime instance FakeTimer.fake(new DateTime(2018, 2, 13, 14, 59)) { } // You can also pass ISODateTimeFormat FakeTimer.fake("2018-03-02T12:34:56+09:00") { } // If you use fakeWithTimer, a timer instance is passed to block. // You can advance time using tick() method. FakeTimer.fakeWithTimer(1515974400000L) { t => println(DateTime.now.toString) // 2018-01-15T00:00:00.000Z t.tick(3000) // Advance time by 3000ms println(DateTime.now.toString) // 2018-01-15T00:00:03.000Z }
Linear Supertypes
Ordering
- Alphabetic
- By Inheritance
Inherited
- FakeTimer
- AnyRef
- Any
- Hide All
- Show All
Visibility
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def fake[T](t: String)(block: => T): T
Fakes DateTime.now by specified ISODateTimeFormat string
Fakes DateTime.now by specified ISODateTimeFormat string
e.g. TimeFaker.fake("2018-03-01T12:34:56") { }
- def fake[T](t: DateTime)(block: => T): T
Fakes DateTime.now by specified DateTime object.
- def fake[T](timeMillis: Long)(block: => T): T
Fakes DateTime.now only in passed block by specified timeMillis.
Fakes DateTime.now only in passed block by specified timeMillis.
Time will be restored after block.
- def fakeWithTimer[T](t: String)(block: (FakeTimer) => T): T
ISODateTimeFormat string version of fakeWithTimer
- def fakeWithTimer[T](t: DateTime)(block: (FakeTimer) => T): T
DateTime object version of fakeWithTimer
- def fakeWithTimer[T](timeMillis: Long)(block: (FakeTimer) => T): T
Fakes DateTime.now by specified timeMillis.
Fakes DateTime.now by specified timeMillis.
This method passes FakeTimer instance to block, so you can advance time by tick method.
FakeTimer.fakeWithTimer(1515974400000L) { t => t.tick(3000) // Advance time by 3000ms }
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated