nscala-time / nscala-time Goto Github PK
View Code? Open in Web Editor NEWA new Scala wrapper for Joda Time based on scala-time
License: Apache License 2.0
A new Scala wrapper for Joda Time based on scala-time
License: Apache License 2.0
Are these omissions?
According to the joda-time website
Joda-Time is the de facto standard date and time library for Java. From Java SE 8 onwards, users are asked to migrate to java.time (JSR-310).
import scala.concurrent.duration._
import com.github.nscala_time.time.Imports._
val timeoutx = 5.seconds
leads to
[error] Note that implicit conversions are not applicable because they are ambiguous:
[error] both method DurationInt in package duration of type (n: Int)scala.concurrent.duration.package.DurationInt
[error] and method RichInt in trait IntImplicits of type (n: Int)com.github.nscala_time.time.RichInt
[error] are possible conversion functions from Int(5) to ?{def seconds: ?}
[error] val timeoutx = 5.seconds
Are there plans to add support for PeriodFormatterBuilder ?
Why there is no the millis equivalent to second in RichDateTime ? That could be nice ^^
Can you add so?
val a=DateTime()
val b=DateTime()
val c=a max b
Thanks
This is not necessary to do because Scala 2.9.3 and 2.9.2 are almost binary compatible.
But there is advantages for users if support 2.9.3. for example mongodb/casbah@417433c#L1R125
nscala-time_2.10-0.2.0.pom contains following elements
<dependency>
<groupId>com.jsuereth</groupId>
<artifactId>xsbt-gpg-plugin</artifactId>
<version>0.6</version>
</dependency>
Hi!
I understand this can't exist in Java, but in Scala I found I can define things like:
implicit class DateTimeUtils(val date: DateTime) extends AnyVal
{
def <= (other: DateTime) = date.compareTo(other) <= 0
}
To have common things like <= available for DateTime objects.
That said, I'm very new to Scala and I'm not sure what you guys are planning, so I wanted to ask about this feature.
please...
Hi!
Recently I've seen something missing from this library, the ability to add a duration to a date time. I've written an extension class for this myself, but maybe something similar could be added to nscala-time? If you think that's cool, I could probably work in a PR to add this feature.
import scala.concurrent.duration.FiniteDuration
import org.joda.time.DateTime
object DateTimeSyntax {
implicit class RichDateTime(dateTime: DateTime) {
def minus(duration: FiniteDuration): DateTime = dateTime.minusMillis(duration.toMillis.toInt)
def -(duration: FiniteDuration): DateTime = minus(duration)
def plus(duration: FiniteDuration): DateTime = dateTime.plusMillis(duration.toMillis.toInt)
def +(duration: FiniteDuration): DateTime = plus(duration)
}
}
Hi!
I'm using nscala-time with RxScala, so I had to write a simple implicit conversion:
import com.github.nscala_time.time.Imports.{ Duration => NscalaDuration }
import scala.concurrent.duration._
object NscalaDurationImplicits {
implicit def Dur2Dur(d: NscalaDuration) : Duration = d.getStandardSeconds() seconds
}
I think it's possible to include this conversion into nscala-time
I think it would be useful to have a method to convert an interval to immutable collection of dates, like SortedSet, with specified step. The main goal is to be able to utilize Scala collections API out of the box
(start to end).toSeq(step).map(date => ???)
Documentation doesn't specify how to obtain UTC time
PR pending.
What's the best way is to convert from an Interval
to a FiniteDuration
(used in the standard library)? Related to that, could there be an implicit conversion for this?
Hello,
I don't know if it's possible but it's can be greate to have an implicit converter from org.joda.time.Duration to scala.concurrent.duration.Duration
It seems sad that this was a fork from scala-time but did not actually fork it (and then rename/move files).
It seems that scala-time is active and it would be good to see the differences between the projects in a network graph.
It would be really cool if:
It'd just be nice to see the differences easily - perhaps nscala-time could commit back - scala-time seems to have a larger community (certainly a larger committer/fork base)
It could be nice to support Java 8 date and time API which is pretty much a copy of Joda Time.
This also means no external dependencies.
We need a website for documents (scaladoc, tutorial, sxr, etc.) ?
To support something like
import com.github.nscala_time.time.Imports._
val duration: Duration = 2 * 2.seconds + 4 * 3.seconds
because long can contain timestamp, is it wise to add .toDateTime on Long ?
At the moment ScalaJS allows to use either javascript Date class or java.util.Date classes. That is why for cross scala-scalajs libraries one has to use only terrible default java.util.Date class :-(
Is it possible to get the first and last day of the week using this library?
Ex.
Input: 4/30/15 (Thursday)
Output: 4/26/15 (Sunday) and 5/2/15 (Saturday).
Can I do something like DateTime.now in interval
instead of interval.contains(date)
?
If not I'll be glad to contribute.
support code like this :
var date1= ...
var date2= ...
date1 max date2'
or maybe
max(date1,date2)
same thing for min operation
You guys can be part of type level also?
DurationBuilder is a leaky abstraction. Many methods will return a DurationBuilder, yet it is private. This makes adding any sugar on Duration and Period difficult (impossible?).
For example:
private val adapt = ((_:Any) match {
case interval: Interval => interval.toDuration
case period: Period => period.toStandardDuration
case other => other
})
def haveTheSameDurationAs(expected: Duration) = be_==(expected) ^^ adapt
def haveTheSameDurationAs(expected: Period) = be_==(expected.toStandardDuration) ^^ adapt
abutting.period must haveTheSameDurationAs(15.hours + 30.minutes) // compile error
Because 15.hours + 30.minutes is a DuratonBuilder. What I need to define is:
def haveTheSameDurationAs(expected: DurationBuilder) = be_==(expected: Duration) ^^ adapt
But I cannot because DurationBuilder is private.
Another example of leaking:
val x = 10.hours + 5.hours
// What type is x? If we let IDEA tell us, we get
val x: DurationBuilder = 10.hours + 5.hours
// Which of course will not compile
How about creation of scala wrapper for new java time api (threeten), which will be added in java 8 ?
Now, nscala-time_2.10.0-0.2.0 is published.
So, who use nscala-time with sbt0.12.x can not resolve dependency without cross CrossVersion.full
.
Insted, sbt0.11.x users can resolve it as README.md
That default usage target sbt0.12.x users basically, regards me as good.
So it should like publish nscala-time for 2.10.0 as binary version 2.10 and follow sbt0.11.x users up by documents.
Existing toDateTime
in RichLong
always uses default time zone which is not always what is desired. For using custom time zone it's necessary to do double call like 123.toDateTime.toDateTime(DateTimeZone.UTC)
which doesn't look nice.
So my request is to please add more toDateTime helper which also accept DateTimeZone.
Hello guys,
I was wondering when you plan to make a new release supporting joda time 2.4?
I'm trying to use this library in combination with slick-joda-mapper which has a dependency on joda-time 2.4 and joda-convert 1.6.
Can't seem to access the DateTime.parse() static method from this lib. It's present in Joda Time as a static method.
The current version of nscala-time
is incompatible with JDK 1.8u60. AWS Java SDK - AWS authentication requires a valid Date or x-amz-date header
I see HEAD has updated the joda-time
dependency but that version has not been released yet. It would be great if nscala-time
updates for Scala 2.10 & 2.11 of could be released soon.
Hello,
I'd like to know when will there be a new release of the lib? I can see that the latest joda has been added in March but no release has been made since December last year.
I use scalikejdbc and there the dependencies are for 2.9.9.
Can you please make a new release and possibly add that to maven central?
Thank you!
code
import com.github.nscala_time.time.Imports._
24.hour
24.hour.millis
1.day
1.day.millis
results:
import com.github.nscala_time.time.Imports._
res0: com.github.nscala_time.time.DurationBuilder = com.github.nscala_time.time.DurationBuilder@fef68c09
res1: Long = 86400000
res2: org.joda.time.Period = P1D
res3: Int = 0
We need the fix of #83 here. Can only get it from 1.9.0-SNAPSHOT now. Hope the next stable version could come out soon.
I have a problem, when I want to find the period between two dates, and subtract some other date by this period, I will get different answer when I choose different date. For example:
val t1 = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").parseDateTime("2017-6-13 12:00:00")
val t2 = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").parseDateTime("2017-07-30 12:00:00")
val t3 = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").parseDateTime("2017-07-31 12:00:00")
t2 - (t1 to t2).toPeriod // 2017-06-13T12:00:00.000+08:00 It's OK, just give me the time of t1
t3 - (t1 to t3).toPeriod // 2017-06-12T12:00:00.000+08:00 It's weird !?? Why I miss one day !??
Recently joda-time 2.2 was released.
I get an error when trying to add a period to a DateTime using nscala-time 0.4.2 with Scala 2.10.2:
scala> import com.github.nscala_time.time.Imports._
scala> DateTime.now + 2.months
<console>:17: error: type mismatch;
found : org.joda.time.DateTime
required: ?{def +(x$1: ? >: org.joda.time.Period): ?}
Note that implicit conversions are not applicable because they are ambiguous:
both method dt2rd in package time of type (dt: org.joda.time.DateTime)org.saddle.time.RichDT
and method RichDateTime in trait JodaImplicits of type (dt: org.joda.time.DateTime)com.github.nscala_time.time.RichDateTime
are possible conversion functions from org.joda.time.DateTime to ?{def +(x$1: ? >: org.joda.time.Period): ?}
DateTime.now + 2.months
^
<console>:17: error: value + is not a member of org.joda.time.DateTime
DateTime.now + 2.months
Please add this method to class RichDateTime :
def dayOfYear: DateTime.Property = underlying.dayOfYear
Edit : add also
def withDayOfYear(doy: Int) = underlying.withDayOfYear(doy)
Is there any way we could publish the current version, since the latest change could be useful for many...
If one big object has too many implicit converions, it sometimes confuses users (including me) and it seems that some of their implicit conversions don't work well.
For example, I experienced that some implicit conversions works well in REPL but doesn't work well in a test (Perhaps, it maybe my error).
See details: #29 (comment)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.