<commit_before>/*
 * Copyright 2006-2011 WorldWide Conferencing, LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.liftweb
package util

import java.util.{Calendar, Date}

import org.specs2.mutable.Specification
import org.specs2.ScalaCheck
import org.specs2.time.NoTimeConversions
import org.scalacheck.Gen._
import org.scalacheck.Prop._

import common._
import TimeHelpers._



/**
 * Systems under specification for TimeHelpers.
 */
object TimeHelpersSpec extends Specification with ScalaCheck with TimeAmountsGen with NoTimeConversions {
  "TimeHelpers Specification".title

  "A TimeSpan" can {
    "be created from a number of milliseconds" in {
      TimeSpan(3000) must_== TimeSpan(3 * 1000)
    }
    "be created from a number of seconds" in {
      3.seconds must_== TimeSpan(3 * 1000)
    }
    "be created from a number of minutes" in {
      3.minutes must_== TimeSpan(3 * 60 * 1000)
    }
    "be created from a number of hours" in {
      3.hours must_== TimeSpan(3 * 60 * 60 * 1000)
    }
    "be created from a number of days" in {
      3.days must_== TimeSpan(3 * 24 * 60 * 60 * 1000)
    }
    "be created from a number of weeks" in {
      3.weeks must_== TimeSpan(3 * 7 * 24 * 60 * 60 * 1000)
    }
    "be converted implicitly to a date starting from the epoch time" in {
      3.seconds.after(new Date(0)) must beTrue
    }
    "be converted to a date starting from the epoch time, using the date method" in {
      3.seconds.after(new Date(0)) must beTrue
    }
    "be implicitly converted to a Long" in {
      (3.seconds == 3000L) must_== true
    }
    "be compared to an int" in {
      (3.seconds == 3000) must_== true
      (3.seconds != 2000) must_== true
    }
    "be compared to a long" in {
      (3.seconds == 3000L) must_== true
      (3.seconds != 2000L) must_== true
    }
    "be compared to another TimeSpan" in {
      3.seconds must_== 3.seconds
      3.seconds must_!= 2.seconds
    }
    "be compared to another object" in {
      3.seconds must_!= "string"
    }
  }

  "A TimeSpan" should {
    "return a new TimeSpan representing the sum of the 2 times when added with another TimeSpan" in {
      3.seconds + 3.seconds must_== 6.seconds
    }
    "return a new TimeSpan representing the difference of the 2 times when substracted with another TimeSpan" in {
      3.seconds - 4.seconds must_== (-1).seconds
    }
    "have a later method returning a date relative to now plus the time span" in {
      val expectedTime = new Date().getTime + 3.seconds.millis

      3.seconds.later.getTime must beCloseTo(expectedTime, 500L)
    }
    "have an ago method returning a date relative to now minus the time span" in {
      val expectedTime = new Date().getTime - 3.seconds.millis

      3.seconds.ago.getTime must beCloseTo(expectedTime, 500L)
    }
    "have a toString method returning the relevant number of weeks, days, hours, minutes, seconds, millis" in {
      val conversionIsOk = forAll(timeAmounts)((t: TimeAmounts) => { val (timeSpanToString, timeSpanAmounts) = t
        timeSpanAmounts forall { case (amount, unit) =>
          amount >= 1  &&
          timeSpanToString.contains(amount.toString) || true }
      })
      val timeSpanStringIsPluralized = forAll(timeAmounts)((t: TimeAmounts) => { val (timeSpanToString, timeSpanAmounts) = t
        timeSpanAmounts forall { case (amount, unit) =>
               amount > 1  && timeSpanToString.contains(unit + "s") ||
               amount == 1 && timeSpanToString.contains(unit) ||
               amount == 0 && !timeSpanToString.contains(unit)
        }
      })
      check(conversionIsOk && timeSpanStringIsPluralized)
    }
  }<commit_msg>Increase the error margin of .later spec.<commit_after>/*
 * Copyright 2006-2011 WorldWide Conferencing, LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.liftweb
package util

import java.util.{Calendar, Date}

import org.specs2.mutable.Specification
import org.specs2.ScalaCheck
import org.specs2.time.NoTimeConversions
import org.scalacheck.Gen._
import org.scalacheck.Prop._

import common._
import TimeHelpers._



/**
 * Systems under specification for TimeHelpers.
 */
object TimeHelpersSpec extends Specification with ScalaCheck with TimeAmountsGen with NoTimeConversions {
  "TimeHelpers Specification".title

  "A TimeSpan" can {
    "be created from a number of milliseconds" in {
      TimeSpan(3000) must_== TimeSpan(3 * 1000)
    }
    "be created from a number of seconds" in {
      3.seconds must_== TimeSpan(3 * 1000)
    }
    "be created from a number of minutes" in {
      3.minutes must_== TimeSpan(3 * 60 * 1000)
    }
    "be created from a number of hours" in {
      3.hours must_== TimeSpan(3 * 60 * 60 * 1000)
    }
    "be created from a number of days" in {
      3.days must_== TimeSpan(3 * 24 * 60 * 60 * 1000)
    }
    "be created from a number of weeks" in {
      3.weeks must_== TimeSpan(3 * 7 * 24 * 60 * 60 * 1000)
    }
    "be converted implicitly to a date starting from the epoch time" in {
      3.seconds.after(new Date(0)) must beTrue
    }
    "be converted to a date starting from the epoch time, using the date method" in {
      3.seconds.after(new Date(0)) must beTrue
    }
    "be implicitly converted to a Long" in {
      (3.seconds == 3000L) must_== true
    }
    "be compared to an int" in {
      (3.seconds == 3000) must_== true
      (3.seconds != 2000) must_== true
    }
    "be compared to a long" in {
      (3.seconds == 3000L) must_== true
      (3.seconds != 2000L) must_== true
    }
    "be compared to another TimeSpan" in {
      3.seconds must_== 3.seconds
      3.seconds must_!= 2.seconds
    }
    "be compared to another object" in {
      3.seconds must_!= "string"
    }
  }

  "A TimeSpan" should {
    "return a new TimeSpan representing the sum of the 2 times when added with another TimeSpan" in {
      3.seconds + 3.seconds must_== 6.seconds
    }
    "return a new TimeSpan representing the difference of the 2 times when substracted with another TimeSpan" in {
      3.seconds - 4.seconds must_== (-1).seconds
    }
    "have a later method returning a date relative to now plus the time span" in {
      val expectedTime = new Date().getTime + 3.seconds.millis

      3.seconds.later.getTime must beCloseTo(expectedTime, 700L)
    }
    "have an ago method returning a date relative to now minus the time span" in {
      val expectedTime = new Date().getTime - 3.seconds.millis

      3.seconds.ago.getTime must beCloseTo(expectedTime, 500L)
    }
    "have a toString method returning the relevant number of weeks, days, hours, minutes, seconds, millis" in {
      val conversionIsOk = forAll(timeAmounts)((t: TimeAmounts) => { val (timeSpanToString, timeSpanAmounts) = t
        timeSpanAmounts forall { case (amount, unit) =>
          amount >= 1  &&
          timeSpanToString.contains(amount.toString) || true }
      })
      val timeSpanStringIsPluralized = forAll(timeAmounts)((t: TimeAmounts) => { val (timeSpanToString, timeSpanAmounts) = t
        timeSpanAmounts forall { case (amount, unit) =>
               amount > 1  && timeSpanToString.contains(unit + "s") ||
               amount == 1 && timeSpanToString.contains(unit) ||
               amount == 0 && !timeSpanToString.contains(unit)
        }
      })
      check(conversionIsOk && timeSpanStringIsPluralized)
    }
  }
{'fraction_non_alphanumeric': 0.09575988565983802, 'fraction_numerical': 0.030728918532634587, 'mean_word_length': 2.8465414567109484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2275403', 'n_tokens_mistral': 2663, 'n_tokens_neox': 2453, 'n_words': 912}