Permalink
Browse files

umm?

  • Loading branch information...
1 parent 82a6cf1 commit 14afe87217b0dbdaca2d563610f740b8b351435b @gangeli committed Jul 28, 2011
Showing with 139 additions and 37 deletions.
  1. +7 −0 .idea/ant.xml
  2. +1 −1 rc
  3. +1 −0 src/time/Entry.scala
  4. +29 −30 src/time/Time.scala
  5. +6 −6 test/src/time/TestTime.scala
  6. +95 −0 time.iml
View
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="AntConfiguration">
+ <defaultAnt bundledAnt="true" />
+ </component>
+</project>
+
View
2 rc
@@ -53,5 +53,5 @@ function r {
make $@ && ./run
}
function cmd {
- java -cp bin:etc/joda-time.jar:etc/scala-compiler.jar:etc/scala-library.jar:etc/jline.jar time.Time
+ java -cp bin:etc/joda-time.jar:etc/scala-compiler.jar:etc/scala-library.jar:etc/jline.jar:etc/lib.jar time.Time
}
View
@@ -108,6 +108,7 @@ object U {
}
def rand:Double = G.random.nextDouble
+ def randInt(begin:Int,end:Int):Int = G.random.nextInt(end-begin)+begin
private val isInt = """^(\-?[0-9]+)$""".r
private val canInt = """^(\-?[0-9]+\.0+)$""".r
View
@@ -121,11 +121,10 @@ case class Range(begin:Time, end:Time) {
}
}
def ~(o:Any):Boolean = {
- if(o.isInstanceOf[Range]){
- val other:Range = o.asInstanceOf[Range]
- return (this.begin ~ other.begin) && (this.end ~ other.end)
+ o match {
+ case (r:Range) => (this.begin ~ r.begin) && (this.end ~ r.end)
+ case _ => false
}
- return false
}
override def equals(o:Any):Boolean = {
if(o.isInstanceOf[Range]){
@@ -200,17 +199,10 @@ class Duration(val p:ReadablePeriod,private val groundFn:Time=>Range) {
def <(other:Duration) = this.seconds < other.seconds
def >(other:Duration) = this.seconds > other.seconds
def ~(o:Any):Boolean = {
- val other:Duration = if(o.isInstanceOf[ReadablePeriod]){
- new Duration(o.asInstanceOf[ReadablePeriod])
- } else if(o.isInstanceOf[Duration]){
- o.asInstanceOf[Duration]
- } else{
- null
- }
- if(other == null){
- return false;
- } else{
- return this.p.seconds == other.p.seconds
+ o match {
+ case (rp:ReadablePeriod) => rp.seconds == this.p.seconds
+ case (d:Duration) => d.p.seconds == this.p.seconds
+ case _ => false
}
}
override def equals(o:Any):Boolean = {
@@ -422,22 +414,20 @@ case class Time(base:DateTime, offset:Duration, modifiers:List[Time=>Time]) {
def typeTag:Symbol = 'Time
def ~(o:Any):Boolean = {
- if(o.isInstanceOf[Time] || o.isInstanceOf[DateTime]){
- val other:Time = o.asInstanceOf[Time]
- if(this.isGrounded && other.isGrounded) {
- //(case: both grounded)
- return this.ground.getMillis == other.ground.getMillis
- } else if(!this.isGrounded && !other.isGrounded) {
- //(case: both ungrounded)
- val thisOffset:Duration
- = if(this.offset==null) Period.ZERO else this.offset
- val otherOffset:Duration
- = if(other.offset==null) Period.ZERO else other.offset
- return (thisOffset-otherOffset).seconds == 0 &&
- Time.probablyEqual(this.modifiers,other.modifiers)
- }
+ o match {
+ case (dt:DateTime) => this ~ new Time(dt)
+ case (t:Time) =>
+ if(this.isGrounded && t.isGrounded){
+ //(case: both grounded)
+ this.ground.getMillis == t.ground.getMillis
+ } else {
+ //(case: something ungrounded)
+ (0 until 100).map{ i => Time.RANDOM }.forall{ (ground:Time) =>
+ this(ground).ground.getMillis == t(ground).ground.getMillis
+ }
+ }
+ case _ => false
}
- return false
}
override def equals(o:Any):Boolean = {
if(o.isInstanceOf[Time] || o.isInstanceOf[DateTime]){
@@ -628,6 +618,15 @@ object Duration {
object Time {
val DAWN_OF = new Time(new DateTime(Long.MinValue), null, null)
val END_OF = new Time(new DateTime(Long.MaxValue), null, null)
+ def RANDOM = Time(
+ U.randInt(1990,2012),
+ U.randInt(1,13),
+ U.randInt(1,27),
+ U.randInt(0,24),
+ U.randInt(0,60),
+ U.randInt(0,60))
+
+
def apply(base:DateTime) = new Time(base, null, null)
def apply(base:DateTime, offset:Duration) = new Time(base, offset, null)
@@ -236,7 +236,7 @@ class ExamplesSpec extends Spec with ShouldMatchers{
it("works for yesterday"){
val yesterday = catLeft
val target = Range(NOW-DAY,NOW)
- assert( yesterday(NOTIME,NODUR) ~ target )
+ assert( yesterday(TODAY,DAY) ~ target )
}
}
describe("Cat Right") {
@@ -336,26 +336,26 @@ class ExamplesSpec extends Spec with ShouldMatchers{
assert( Time.probablyEqualRange(target,since(may32010,_:Range)) )
}
it("works for Since yesterday"){
- val yesterday = catLeft(NOTIME,NODUR)
+ val yesterday = catLeft(TODAY,DAY)
val since = cons
val target = (r:Range) => Range(NOW-DAY, r.end)
assert( Time.probablyEqualRange(target,since(yesterday,_:Range)) )
}
it("works for Until tomorrow"){
- val tomorrow = catRight(NOTIME,NODUR)
+ val tomorrow = catRight(TODAY,DAY)
val until = cons
val target = (r:Range) => Range(r.begin,NOW+DAY*2)
assert( Time.probablyEqualRange(target,until(_:Range,tomorrow)) )
}
it("works for Before tomorrow"){
- val tomorrow = catRight(NOTIME,NODUR)
+ val tomorrow = catRight(TODAY,DAY)
val before = cons
val target = (r:Range) => Range(r.begin,NOW+DAY*2)
assert( Time.probablyEqualRange(target,before(_:Range,tomorrow)) )
}
it("works for yesterday until tomorrow"){
- val yesterday = catLeft(NOTIME,NODUR)
- val tomorrow = catRight(NOTIME,NODUR)
+ val yesterday = catLeft(TODAY,DAY)
+ val tomorrow = catRight(TODAY,DAY)
val until = cons
val target = Range(NOW-DAY,NOW+DAY*2)
assert( until(yesterday,tomorrow) ~ target )
View
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+ <component name="FacetManager">
+ <facet type="scala" name="Scala">
+ <configuration>
+ <option name="compilerLibraryLevel" value="Global" />
+ <option name="compilerLibraryName" value="scala-compiler-2.9.0.1" />
+ </configuration>
+ </facet>
+ </component>
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/test/src" isTestSource="true" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="scala-library-2.9.0.1" level="application" />
+ <orderEntry type="library" name="JavaNLP" level="application" />
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/etc/postgresql.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/etc/lib.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/etc/joda-time.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/etc/scalatest.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library" scope="RUNTIME">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/etc/models.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library" scope="RUNTIME">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/etc/jline.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library" scope="RUNTIME">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/etc/jdom.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library" scope="RUNTIME">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/etc/scala-compiler.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ </component>
+</module>
+

0 comments on commit 14afe87

Please sign in to comment.