package com.eddsteel.posts.leastpower

import java.time.{LocalDate, ZonedDateTime}

object DateTimeUtils {
  private var overriddenNow: Option[ZonedDateTime] = None

  def now: ZonedDateTime = synchronized {
    overriddenNow.fold(ZonedDateTime.now)(identity)
  }

  def setDateTime(d: ZonedDateTime): Unit = synchronized {
    overriddenNow = Some(d)
  }

  def sameDay(one: LocalDate, two: LocalDate) =
    one.getYear == two.getYear &&
    one.getMonth == two.getMonth &&
    one.getDayOfMonth == two.getDayOfMonth
}