Giter Site home page Giter Site logo

cljs-time's Introduction

cljs-time Build Status

A date and time library for ClojureScript, imitating the API of the clj-time library.

Cljs-time is an attempt at replicating the functionality and API of clj-time. This is not a drop-in clojurescript replacement for clj-time, however the goal is that over time enough functionality of the clj-time API can be replicated to make this library "good enough" for other projects.

This library is currently leaning on the Google Closure goog.date library for basic date/time functionality. The date objects in this library are mutable, however any operations that alter a date object return a copy, leaving the referenced date object alone. In the future, immutable date objects will be preferred.

Artifacts

cljs-time artifacts are released to Clojars.

If you are using Maven, add the following repository definition to your pom.xml:

<repository>
  <id>clojars.org</id>
  <url>http://clojars.org/repo</url>
</repository>

The Most Recent Release

With Leiningen:

;; Stable
[com.andrewmcveigh/cljs-time "0.5.2"]

Bugs and Enhancements

Please open issues against the cljs-time repo on Github.

Note: version 0.5. follows the API of clj-time 0.11.0.*

API

Most of the clj-time API has been implemented. Some of the parts that don't make sense in clojurescript, such as Java interop, and java.sql.* have been left out. Timezone functionality in javascript is minimal, and therefore so is cljs-time's.

The majority of the tests from clj-time have been ported, and are passing.

API documentation is available.

Usage

Note: Equality in goog.date.* (and also with plain javascript dates) is not the same as in Joda/clj-time. Two date objects representing the same instant in time in goog.date.* are not equal.

If you need to test for equality use either cljs-time.core/=, or optionally you can require the cljs-time.extend namespace which will extend the goog.date.* datatypes, so that clojure.core/= works as expected.

If you want your goog.date.* serializable with pr-str, require cljs-time.instant namespace.

cljs-time.core

The main namespace for date-time operations in the cljs-time library is cljs-time.core.

=> (use 'cljs-time.core)

Create a DateTime instance with date-time, specifying the year, month, day, hour, minute, second, and millisecond:

=> (date-time 1986 10 14 4 3 27 456)
#<DateTime 1986-10-14T04:03:27.456Z>

Less-significant fields can be omitted:

=> (date-time 1986 10 14)
#<DateTime 1986-10-14T00:00:00.000Z>

Get the current time with (now) and the start of the Unix epoch with (epoch).

Once you have a date-time, use accessors like hour and second to access the corresponding fields:

=> (hour (date-time 1986 10 14 22))
22

The date-time constructor always returns times in the UTC time zone.

If you only want a date with no time component, consider using the local-date and today functions. These return LocalDate instances that do not have time components (and thus don't suffer from timezone-related shifting).

=> (local-date 2013 3 20)
#<LocalDate 2013-03-20>

The functions after? and before? determine the relative position of two DateTime instances:

=> (after? (date-time 1986 10) (date-time 1986 9))
true

Often you will want to find a date some amount of time from a given date. For example, to find the time 1 month and 3 weeks from a given date-time:

=> (plus (date-time 1986 10 14) (months 1) (weeks 3))
#<DateTime 1986-12-05T00:00:00.000Z>

An Interval is used to represent the span of time between two DateTime instances. Construct one using interval, then query them using within?, overlaps?, and abuts?

=> (within? (interval (date-time 1986) (date-time 1990))
            (date-time 1987))
true

The in-seconds and in-minutes functions can be used to describe intervals in the corresponding temporal units:

=> (in-minutes (interval (date-time 1986 10 2) (date-time 1986 10 14)))
17280

cljs-time.format

If you need to parse or print date-times, use cljs-time.format:

=> (use 'cljs-time.format)

Printing and parsing are controlled by formatters. You can either use one of the built in ISO8601 formatters or define your own, e.g.:

(def built-in-formatter (formatters :basic-date-time))
(def custom-formatter (formatter "yyyyMMdd"))

To see a list of available built-in formatters and an example of a date-time printed in their format:

=> (show-formatters)

Remember that mm is minutes, MM is months, ss is seconds and SSS is milliseconds.

Once you have a formatter, parsing and printing are straight-forward:

=> (parse custom-formatter "20100311")
#<20100311T000000>

=> (unparse custom-formatter (date-time 2010 10 3))
"20101003"

cljs-time.core/today-at returns a moment in time at the given hour, minute and second on the current date:

=> (today-at 12 00)
#<20130329T120000>
=> (today-at 12 00 05)
#<20130329T120005>

cljs-time.coerce

The namespace cljs-time.coerce contains utility functions for coercing Google Closure DateTime instances to and from various other types:

=> (use 'cljs-time.coerce)

For example, to convert a goog.date DateTime to and from a js Number:

=> (to-long (date-time 1998 4 25))
893462400000

=> (from-long 893462400000)
#<19980425T000000>

And by the magic of protocols you can pass in an isoformat string and get the unix epoch milliseconds:

=> (to-long "2013-08-01")
1375315200000

Development

Running the tests:

$ boot test-all

OR

$ boot auto-test

Getting a REPL

$ boot repl # (or jack-in from cider/etc)
    boot.user> (node-repl)
    clojurescript node.js repl server listening on 56950
    to quit, type: :cljs/quit
    nil
    cljs.user> (+ 1 1)
    2

Documentation

The complete API documentation is also available.

License

Copyright © 2013-2016 Andrew Mcveigh

Distributed under the Eclipse Public License, the same as Clojure.

cljs-time's People

Contributors

adamfrey avatar andrewhr avatar andrewmcveigh avatar arichiardi avatar arttuka avatar astine avatar belucid avatar bjeanes avatar bostonaholic avatar danielcompton avatar flyingmachine avatar galdolber avatar johnswanson avatar leppert avatar meeseekz avatar moxaj avatar nblumoe avatar piranha avatar psalaberria002 avatar sgrove avatar shen-tian avatar vikeri avatar vyacheslavmik avatar weiznich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cljs-time's Issues

setYear is not a function when parsing dates

I am pretty sure this is a case of me being dumb, but I am getting an error whenever I try to parse a date:

iwsmith-site.core=> (format/parse (:basic-date format/formatters) "20150501")
#<TypeError: p1__22659_SHARP_.setYear is not a function>
         cljs.core.merge_with.call.cljs_time.internal.core.valid_date_QMARK_.call.cljs.core.reduce.call.vec__22697 (jar:file:/Users/iwsmith/.m2/repository/com/andrewmcveigh/cljs-time/0.3.7/cljs-time-0.3.7.jar!/cljs_time/format.cljs:395:29)
         cljs.core.merge_with.cljs$core$IFn$_invoke$arity$variadic.merge_entry (jar:file:/Users/iwsmith/.m2/repository/org/clojure/clojurescript/0.0-3211/clojurescript-0.0-3211.jar!/cljs/core.cljs:25513:3)
         Function.cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$3 (jar:file:/Users/iwsmith/.m2/repository/org/clojure/clojurescript/0.0-3211/clojurescript-0.0-3211.jar!/cljs/core.cljs:8244:3)
         cljs.core.PersistentArrayMapSeq.cljs$core$IReduce$_reduce$arity$3 (jar:file:/Users/iwsmith/.m2/repository/org/clojure/clojurescript/0.0-3211/clojurescript-0.0-3211.jar!/cljs/core.cljs:5618:28)
         Function.cljs.core.reduce.cljs$core$IFn$_invoke$arity$3 (jar:file:/Users/iwsmith/.m2/repository/org/clojure/clojurescript/0.0-3211/clojurescript-0.0-3211.jar!/cljs/core.cljs:2042:29)

My namespace is configured as follows:

(ns ^:figwheel-always iwsmith-site.core
    (:require [om.core :as om :include-macros true]
              [om.dom :as dom :include-macros true]
              [cljs-time.core :as time]
              [cljs-time.format :as format]
              [sablono.core :as html :refer-macros [html]]))

And project.clj:

[com.andrewmcveigh/cljs-time "0.3.7"]

Thanks for taking a look!

Uncaught TypeError: Cannot read property 'replace' of null

My dependencies

 [com.andrewmcveigh/cljs-time "0.3.14"]
 [org.clojure/clojurescript "1.7.122" :scope "provided"]
  [lein-figwheel "0.4.1"]

Just copy code from README to get start

(def built-in-formatter (formatters :basic-date-time))
(def custom-formatter (formatters "yyyyMMdd"))
(date-time 1986 10 14)
(parse custom-formatter "20100311")

But unfortunately I got following errors in console:

Uncaught TypeError: Cannot read property 'replace' of null
cljs_time$format$old_string_replace @format.cljs:270
cljs_time$format$date_parse_pattern @ format.cljs:270
cljs_time.format.parser_fn @ format.cljs:267
cljs_time$format$parse_STAR_ @format.cljs:401
cljs_time.format.parse.cljs$core$IFn$_invoke$arity$2 @ format.cljs:408
cljs_time$format$parse @ format.cljs:409
(anonymous function) @ components.cljs:24
utils.cljs:36 Figwheel: trying to open cljs reload socket

The first function call works fine,the second one throws an exception.
It is quite strange, I just use some basic api.It may be caused by some environment or version problems,but I have no idea..

Problem with `to-time-zone`

Great library! However, I'm having a problem with the cljs-time.core/to-time-zone method. As far as I can see, goog.date.DateTime doesn't have a withZone method. I spent a few minutes surfing around and it isn't clear to me how to convert a datetime from one timezone to another using the Closure stuff (which I am not very familiar with). Specifically, I am receiving serialized datetimes in UTC and I want to convert them to the local (default) timezone.

parse fails for simple formats yyyy-MM-dd

Below is a rhino-repl example, but I also get this in chrome

$ lein trampoline cljsbuild repl-rhino
Running Rhino-based ClojureScript REPL.
To quit, type: :cljs/quit
cljs.user=> (require '[cljs-time.format :as fmt])
nil
cljs.user=> (def yyyy-MM-dd (fmt/formatter "yyyy-MM-dd"))

'cljs.user/yyyy-MM-dd

cljs.user=> (fmt/parse yyyy-MM-dd "2013-04-01")
org.mozilla.javascript.JavaScriptException: #error {:message "The parser could not match the input string.", :data {:type :parser-no-match}} (.cljs_rhino_repl/goog/../cljs_time/format.js#565)
cljs_time$format$parse_STAR_ (.cljs_rhino_repl/cljs_time/format.cljs:397:9)
(.cljs_rhino_repl/cljs_time/format.cljs:405:6)
cljs_time$format$parse (.cljs_rhino_repl/cljs_time/format.cljs:401:1)
(NO_SOURCE_FILE :1:0)
(NO_SOURCE_FILE :1:0)

Time zone is neglected when formatting

Supplying a time zone to a formatter makes no difference when formatting:

(unparse (formatter "yyyy-MM-dd HH:mm" (time-zone-for-offset 2)) (date-time 2015))
=> 2015-01-01 00:00
(unparse (formatter "yyyy-MM-dd HH:mm" (time-zone-for-offset -2)) (date-time 2015))
=> 2015-01-01 00:00

Same thing when parsing.

Large interval crashes Chrome when calling `in-months`

It seems to not be able to handle an Interval (in months) > 18.

Console
> var start = cljs_time.format.parse(cljs_time.format.formatter("MM/dd/YYYY"), "05/06/2015")
undefined
> var end = cljs_time.format.parse(cljs_time.format.formatter("MM/dd/YYYY"), "05/05/2017")
undefined
> start
g…g.d…e.UtcDateTime {date: Tue May 05 2015 18:00:00 GMT-0600 (MDT)}
> end
g…g.d…e.UtcDateTime {date: Sat May 04 2017 18:00:00 GMT-0600 (MDT)}
> cljs_time.core.interval(start, end);
c…e.c…e.Interval {start: g…g.d…e.UtcDateTime, end: g…g.d…e.UtcDateTime, __meta: null, __extmap: null, __hash: null…}__extmap: null__hash: null__meta: nullcljs$lang$protocol_mask$partition0$: 2229667594cljs$lang$protocol_mask$partition1$: 8192end: goog.date.UtcDateTimestart: goog.date.UtcDateTime__proto__: cljs_time.core.Interval
> cljs_time.core.in_months(cljs_time.core.interval(start, end));
<hang then eventually crash>
Versions

[org.clojure/clojurescript "0.0-3123"]
[com.andrewmcveigh/cljs-time "0.3.5"]

unparse fails with [org.clojure/clojurescript "1.7.122"] due to clojure.string/replace

Tested with com.andrewmcveigh/cljs-time "0.3.11" and clojurescript 1.7.58 and earlier and the following test passes, but fails in 1.7.122 due to clojure.string/replace changes.

(deftest default-basic-time
  (testing "Confirm base cljs-time :basic-time uses zero time, seconds & milliseconds"
    (let [formatter-no-time   (datef/formatters :basic-date)
          formatter-with-time (datef/formatters :basic-date-time)
          iso8601             "20150408"
          from-str            (datef/parse formatter-no-time iso8601)        ; instantiate UTC from string without time
          from-date           (datef/unparse formatter-with-time from-str)]  ; convert back to UTC string with time
      (is (instance? js/goog.date.UtcDateTime from-str))
      (is (= "20150408T000000.000Z" from-date) "We expect UTC time including milliseconds to be zero."))))

unparse fails in rhino repl with a null call error

I tried running the following code in rhino repl but it fails.

clj-demgen.main> (cemerick.piggieback/cljs-repl (cljs.repl.rhino/repl-env))
To quit, type: :cljs/quit
nil
cljs.user> (require '[cljs-time.core :as date])
nil
cljs.user> (require '[cljs-time.format :as date-format])j
nil
cljs.user> (date-format/unparse (date-format/formatters :basic-date-time)
                                 (date/today-at 12 00))
org.mozilla.javascript.EcmaError: TypeError: Cannot call method "call" of null (rhino.clj#41)

Parsing "2014-04-01T14:57:00+01:00" using :date-time-no-ms returns nil

I'm executing this line:

(tf/parse (ft/formatter "yyyy-MM-dd'T'HH:mm:ssZZ") "2014-04-01T14:57:00+01:00")

or

(tf/parse (ft/formatters :date-time-no-ms) "2014-04-01T14:57:00+01:00")

and both cases return nil and throw no exceptions. I'm using cljs-time 0.1.3 and clojurescript 0.0-2173. Is this a bug? The same thing works fine in clj-time:

user> (tf/parse (tf/formatter "yyyy-MM-dd'T'HH:mm:ssZZ") "2014-04-01T14:57:00+01:00")
#<DateTime 2014-04-01T13:57:00.000Z>

Formatter escape character not working

It appears that the escape character ' is not properly escaping the enclosed string when doing unparse.

(cljs-time.format/unparse (cljs-time.format/formatter "'Yesterday:' MMMM dd") (cljs-time.core/yesterday)) => "Y348t3r2amy: September 02"

cljs-time = 0.3.12
cljs = 1.7.58

Missing IHash implementation

I have a usecase where I need to keep dates as keys in a map. When trying to find an entry I sometimes get nil even though the date is present (as indicated by cljs-time.core/=). Sadly, I can't reproduce the behaviour in the repl easily (I receive the map through transit, reading the dates via (goog.date.UtcDateTime.fromIsoString s)).
Everything works if I implement IHash:

(extend-type goog.date.UtcDateTime IHash (-hash [this] (cljs-time.coerce/to-long this)))
(extend-type goog.date.Date IHash (-hash [this] (cljs-time.coerce/to-long this)))
(extend-type goog.date.DateTime IHash (-hash [this] (cljs-time.coerce/to-long this)))

Issue #19 talked about this, but the implementation in cljs-time.extends just focuses on IEquiv and IComparable, leaving out IHash.

show-formatters does not work

Don't know why I am unable to call this function when all the other work well

cljs-tut.core> (f/show-formatters)
"Error evaluating:" (f/show-formatters) :as "cljs_time.format.show_formatters.call(null);\n"

<TypeError: Cannot read property 'call' of undefined>

TypeError: Cannot read property 'call' of undefined
at eval (eval at (http://localhost:8080/js/cljs_tut.js:37557:260), :1:97)
at eval (eval at (http://localhost:8080/js/cljs_tut.js:37557:260), :5:3)
at http://localhost:8080/js/cljs_tut.js:37557:255
at evaluate_javascript (http://localhost:8080/js/cljs_tut.js:37570:4)
at Object.callback (http://localhost:8080/js/cljs_tut.js:37635:181)
at goog.messaging.AbstractChannel.deliver (http://localhost:8080/js/cljs_tut.js:35417:13)
at goog.net.xpc.CrossPageChannel.xpcDeliver (http://localhost:8080/js/cljs_tut.js:36959:14)
at Function.goog.net.xpc.NativeMessagingTransport.messageReceived_ (http://localhost:8080/js/cljs_tut.js:36373:13)
at goog.events.Listener.handleEvent (http://localhost:8080/js/cljs_tut.js:30374:26)
at Object.goog.events.fireListener (http://localhost:8080/js/cljs_tut.js:30751:19)
nil

handle nils same way as clj-time

Some of the functions in cljs-time will NPE while the equivalent clj-time functions will handle nils intelligently. For example, from-date in clj-time does a when check on the date. I think this is very valuable as it allows you to safely chain the functions without having to pepper nil checks in-between.

Week number in year is wrong

Hi, I found an issue with formatters, like :weekyear-week. It spreads across all formatters, that uses ww (week number). Current implementation does not follow ISO 8601.

It is actually very easy to fix the issue, because Google Closure library is already implement required method. Just change this line to:

  "ww" #(.getWeekNumber %)

time-format/date-parsers returns nil on iPhone 4

@Jell:
I'm asking because I've been tracking down a bug I found on iPhone 4 that I've been pulling my hair on for 2 days straight, and I don't know the exact details of why but this:

(time-format/date-parsers "yyyy")

Returns nil if and only if I run it on an iphone 4 without using the debugger. If I use the debugger it works again.

So I have no idea why, but if I wrap date-parsers in a (defn) the problem goes away. I suspect it has something to do with the naked top level let, as mentioned in this issue. Do you mind if I provide a PR where I wrap all the top level hashes in a defn?

Incorrect calculation of months over a long interval

I have updated the cljs-time.core-test/long-interval-test to show it failing.

(deftest long-interval-test
  (let [start (date-time 2015 5 6)
        end (date-time 2024 5 5)
        i (interval start end)]
    (is (= 108 (in-months i)))))
FAIL in (cljs-time.core-test/long-interval-test) (:)
expected: (= 108 (in-months i))
  actual: (not (= 108 102))

Also, unrelated (but maybe not), the test suite does not pass for me aside from the one above. I get 3 failures, all the same from each of the different compilations.

FAIL in (cljs-time.core-test/test-today-default) (:)
expected: (= (local-date 2013 4 20) (do-at (to-default-time-zone (date-time 2013 4 20)) (today)))
  actual: (not (= #<20130420> #<20130419>))

= function moved to internal namespace

It's really important to be able to check dates for equality, so it makes sense for the = fn to exist in the core namespace. Or perhaps I'm missing some rationale for the move?

unparse giving wrong result

(ns foo
  (:require [cljs-time.format :as f]
                 [cljs-time.coerce :as c]))

(def date-formatter (f/formatter "MM/DD/YYYY"))
(defn str->date [date-as-str]
  (->> date-as-str (f/parse date-formatter) c/to-date))

(defn date->str [date]
  (->> date c/from-date (f/unparse date-formatter) ))

(-> "06/23/2016" str->date date->str) ;;evaluates to "06/175/2016" when the original  "06/23/2016" is expected

Am I using unparse incorrectly? why does it give "06/175/2016" and not "06/23/2016"?. I am using [org.clojure/clojurescript "1.9.76"]

formatter A broken

0.3.4
It goes from 5:00 PM to 5:00 AM.

(def my-time (f/parse (f/formatter "h:mm A") "5:00 PM")) ; => #<00101T050000>
(f/unparse (f/formatter "h:mm A") my-time) ; => "5:00 AM"

pulls in dev dependencies?

When I do lein deps :tree, I see:

[com.andrewmcveigh/cljs-time "0.5.0-alpha1"]
   [adzerk/boot-cljs "1.7.228-1"]
   [doo "0.1.7-20160306.211039-2"]
     [karma-reporter "0.1.0"]
   [funcool/boot-codeina "0.1.0-20150517.155946-4"]
     [hiccup "1.0.5"]
     [leinjacker "0.4.2"]
       [org.clojure/core.contracts "0.0.1"]
         [org.clojure/core.unify "0.5.3"]
     [org.clojure/tools.namespace "0.2.10"]
     [org.pegdown/pegdown "1.4.2"]
       [org.parboiled/parboiled-java "1.1.6"]
         [org.ow2.asm/asm-analysis "4.1"]
         [org.ow2.asm/asm-tree "4.1"]
         [org.ow2.asm/asm-util "4.1"]
         [org.ow2.asm/asm "4.1"]
         [org.parboiled/parboiled-core "1.1.6"]

I'm assuming I can just exclude those. Is there a way to remove those deps from the artifact when it's included in a project?

Library should not contain top level data structures, defeats Closure DCE, use functions instead

Namespaces like cljs-time.format should not use top level data structures. This will immediately defeat Closure dead code elimination. Top level static JavaScript objects have the benefit of being optimizable by Google Closure so this pattern is acceptable in Closure itself - this is not true for PersistentHashMaps etc. These top level data structures should be replaced by proper functions.

For smaller libraries this is not a problem, but for cljs-time where the surface area is quite large this will be an issue for potential consumers.

no date hashing?

Hashing of dates seems to be broken/non-existent, probably due to use of Google JS types. The following should produce a map of 3 pairs (12h steps, grouped by day), but instead does no grouping at all:

(->> (now)
     (to-long)
     (iterate #(+ % (* 12 60 60 1000)))
     (interleave '[a b c d e f])
     (partition 2)
     (group-by
       (fn [[_ t]]
        (let [d (from-long t)]
          (date-midnight (year d) (month d) (day d))))))

{#<20150106T000000> [(a 1420512947185)],
 #<20150106T000000> [(b 1420556147185)],
 #<20150107T000000> [(c 1420599347185)],
 #<20150107T000000> [(d 1420642547185)],
 #<20150108T000000> [(e 1420685747185)],
 #<20150108T000000> [(f 1420728947185)]}

The same works in Clojure w/ clj-time:

{#<DateMidnight 2015-01-06T00:00:00.000Z> [(a 1420513336586) (b 1420556536586)],
 #<DateMidnight 2015-01-07T00:00:00.000Z> [(c 1420599736586) (d 1420642936586)],
 #<DateMidnight 2015-01-08T00:00:00.000Z> [(e 1420686136586) (f 1420729336586)]}

A simple fix might be to add an IHash protocol impl based on epochs...

Consider using cljs-time.core/equal? as well as cljs-time.core/=

Hi, thanks for creating cljs-time, excellent work. 👍

I wanted to ask if there is a reason why you can't consider using cljs-time.core/equal? as well as cljs-time.core/=. This would bring the API inline with what clj-time uses.

I'm currently making use of reader conditionals to use either clj-time.core/equal? or cljs-time.core/=, it would be cool to not have to do this.

Thanks!

TypeError: Cannot read property 'from_long' of undefined

I'm having trouble using the from-long function. In fact nothing from coerce is working.

(cljs-time.core/date-time 1986 10 14 22)
#<19861014T220000>
(cljs-time.coerce/from-long 893462400000)
#<TypeError: Cannot read property 'from_long' of undefined>

Compiler exception when adding to boot dependencies

I get the following error after adding the cljs-time dependecy to build.boot:

clojure.lang.Compiler$CompilerException: java.lang.IllegalArgumentException:
No single method: _setup of interface: cljs.repl.IJavaScriptEnv found for function:
-setup of protocol: IJavaScriptEnv, compiling:(cemerick/piggieback.clj:149:5)

java.lang.IllegalArgumentException: No single method: _setup of interface:
cljs.repl.IJavaScriptEnv found for function: -setup of protocol: IJavaScriptEnv

Full output is available here https://gist.github.com/nblumoe/b7667ce2072f0d811196

Is this a cljs-time issue?

.indexOf is not available for IE8

Hi
Thanks for the great library, we've been using it in production lately, just happen to notice failure from use of unavailable javascript array method .indexOf for IE8.

I wasn't sure what your preferred solution for it, but incase you are already working on it I thought I should just flag it up as issue. (detail of the .indexOf below in mozilla js reference page)

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf

thanks!

J

goog.date.duration

just FYI, someone inquired on #clojurescript clojurians slack:

Does anyone have a "time remaining" function lying around that humanises seconds to "5 days", "4 hours", "32 minutes"? Would save me some time.

Looks like goog.date.duration does this and might be nice to include in cljs-time.

with-locale

According to the documentation, in order to print datetimes according to a locale, "with-locale" should be used

The thing is I can't find with-locale in the code. Is it there ?

Support setting client clock skew

Often, clients have incorrect times and zones. For many applications, it is essential to deal with the server time; the client time is irrelevant.

It would be great if now, today, etc. could use custom time and zone settings instead of relying on the client's default settings. Would you be interested in a PR that adds this functionality?

(instant-map) function has negative days

Hi,

clj-time "0.10.0"

When passing an interval that spans across more than a year to the function (instant->map) the :day field of the map has a negative number. It works in clj.time

I believe if the end date passed to the deftest function (in format_test) was changed from '1986' to '1987' it will show this error?

Thanks

Adding IComparable to cljs-time.extend

I think it would be worth it. I've implemented it in my app like that:

(extend-type goog.date.DateTime
  IComparable
  (-compare [o other]
    (- (.getTime o) (.getTime other))))

IComparable and IEquiv not correct for goog.date.Date

Currently .getTime is used to get the value that will be tested. But if the date was created using .setTime like in today comparison and equality test will not work correctly.

I am working on a patch that will solve this issue, will add some tests that shows this functionality. PR incoming.

Problem using minus with months

Hi, I'm working with quarters for a project of my company and i found something that may be a bug.
Here are the steps to reproduce:

cljs.user=> (require '[cljs-time.core :as t])
cljs.user=> (def starting-date (t/date-time 2015 10))
#'cljs.user/starting-date
cljs.user=> starting-date
#object[Object 20151001T000000]
cljs.user=> (t/minus starting-date (t/months (* 6 3)))
#object[Object 20140401T000000]
cljs.user=> (t/minus starting-date (t/months (* 7 3)))
#object[Object 20130101T000000]

As you can see if you do 2015/10/01 minus 18 months (6 * 3) you get 2014/04/01 that is correct but if you subtract 21 months (7 * 3) you get 2013/01/01 that is incorrect, it should be 2014/01/01 or 2013/12/31 (or something like that).

Do you think this is a bug or I'm using it the wrong way?

I noticed that `lein cljsbuild once min` stops generating the js file.

I noticed that lein cljsbuild once min stops generating the js file.

Moreover with 0.3.15 I have:

Compiling "resources/public/js/compiled/lambdax_web.js" from ["src/cljs" "env/prod/cljs"]...
WARNING: No such namespace: goog.i18n.TimeZone, could not locate goog/i18n/TimeZone.cljs, goog/i18n/TimeZone.cljc, or Closure namespace "" at line 241 /home/kapitan/git/lambdax-web/target/cljsbuild-compiler-1/cljs_time/core.cljs
WARNING: Use of undeclared Var goog.i18n.TimeZone/createTimeZone at line 241 /home/kapitan/git/lambdax-web/target/cljsbuild-compiler-1/cljs_time/core.cljs

cljs-time.core is nil?!

I have no idea what's going on here. Using [com.andrewmcveigh/cljs-time "0.3.11"]. FWIW, the format ns isn't just non-nil -- it's fully functional.

cljs.user=> (require 'cljs-time.core)
nil
cljs.user=> (require 'cljs-time.format)
nil
cljs.user=> (require 'cljs-time.coerce)
nil
cljs.user=> (map some? [cljs-time.core cljs-time.format cljs-time.coerce])
(false true true)

Consider using the date parser from date.js

Datejs has an absolutely amazing date parser that reliably parses a wide variety of user input without having to pre-specify the format. I think it would be a bit of a project to port it, but it may be possible to just use the existing javascript directly if the licensing terms are compatible.

It's on Github at https://github.com/datejs/Datejs. The original author seems to have gone away a few years ago, but some people have been maintaining their own forks to some degree, though I don't know if they represent a major improvement over the original, though at least one minor parsing bug has been fixed that I've seen.

I've spent a lot of time researching this because I was considering doing this myself. From what I can tell, Datejs is in a league of its own, far better than anything else out there. Unfortunately I decided that I just don't have the time to take this on right now.

If someone were to bring that parser into this project, I think it would be a huge contribution to the ClojureScript community...

Equality seems broken

I've noticed that comparing 2 dates using = doesn't work as expected in most cases. I understand there are mutable objects underneath, but even instance equality (I.e. comparing the same instance to itself) returns false, which just seems weird. I dug through the source and found an implementation of = that does what I would expect, but of course that relies on explicitly calling that version of = and that doesn't work in a large number of cases.

I fixed this in my code by implementing IEquiv and everything works great now. I was just curious why the library doesn't do that in the first place? Was this a conscious design choice, and if so what drove the decision?

When given a day that is outside the range of a month (31/04/2013) it parses it as the first of the next month (01/05/2013) instead of failing.

Hi. Thanks for putting this together!

We are using cljs-time in order to use the same validation in the back- and frontend.
While doing that we discovered that cljs-time behaves differently from clj-time in the way it parses dates.

When given a day that is outside the range of a month (31/04/2013) it parses it as the first of the next month (01/05/2013) instead of reporting it as invalid, which is clj-time behavior.
Also you can put any number as a day and it will then wrap that around (mod 31, I guess) and use that. So the 32/04/2013 will be parsed as being valid and return the date 01/04/2014.

Here is some example code, tested in a chrome console.

var f = cljs_time.format.formatter("dd/MM/yyyy");
cljs_time.format.parse(f, "31/04/2013");
=> goog.date.UtcDateTime {date: Wed May 01 2013 01:00:00 GMT+0100 (BST), }

cljs_time.format.parse(f, "32/04/2013")
=> goog.date.UtcDateTime {date: Mon Apr 01 2013 01:00:00 GMT+0100 (BST), }

Cheers,
Waldemar

Inconsistent cljs-time.coerce/to-date behavior relative to clj-time when calling to-date on goog.date.DateTime

Hi, unclear if this is intentional or unavoidable but just for documentation of one difference between the two since it may be the cause of future confusion for other users.

;; In Clojure, on server side JVM using clj-time
> (clj-time.coerce/to-date (clj-time.core/now))
#inst "2015-05-15T02:44:59.957-00:00"
> (clj-time.coerce/to-date (clj-time.local/local-now))
#inst "2015-05-15T02:45:04.054-00:00"

;; In ClojureScript in browser using cljs-time
cljs.user> (cljs-time.coerce/to-date (cljs-time.local/local-now))
#inst "2015-05-14T19:44:40.494-00:00"
cljs.user> (cljs-time.coerce/to-date (cljs-time.core/now))
#inst "2015-05-15T02:44:45.378-00:00"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.