Packages

p

com.github.shibayu36

jodatimefake

package jodatimefake

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. Protected

Type Members

  1. class FakeTimer extends AnyRef

    FakeTimer class to advance time in fakeWithTimer

Value Members

  1. object FakeTimer

    Provides utility methods to fake current time of org.joda.time.DateTime.

    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
    }

Ungrouped