Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unparse giving wrong result #66

Closed
sonwh98 opened this issue Jun 24, 2016 · 2 comments
Closed

unparse giving wrong result #66

sonwh98 opened this issue Jun 24, 2016 · 2 comments

Comments

@sonwh98
Copy link

sonwh98 commented Jun 24, 2016

(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"]

@sonwh98
Copy link
Author

sonwh98 commented Jun 24, 2016

used moment.js instead

(require  [cljsjs.moment])

(defn str->date [date-as-str]
  (let [m (-> date-as-str (js/moment. "MM/DD/YYYY"))]
    (. m toDate)))

(defn date->str [date]
  (.. (js/moment. date) (format "MM/DD/YYYY")))

@andrewmcveigh
Copy link
Owner

The pattern DD means day of the year. Lowercase dd is what you want for day
of month.

On Fri, 24 Jun 2016 05:14 Sonny To, notifications@github.com wrote:

used moment.js instead

(require [cljsjs.moment])

(defn str->date [date-as-str](let [m %28-> date-as-str %28js/moment.))]
(. m toDate)))

(defn date->str [date](.. %28js/moment. date%29 %28format)))


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#66 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AALnm4T3NA6ywnIJotovG1jHxeoOHZqkks5qO1mggaJpZM4I9cO0
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants