Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 502649467 for ; Wed, 5 Oct 2011 07:30:43 +0000 (UTC) Received: (qmail 75316 invoked by uid 500); 5 Oct 2011 07:30:41 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 75257 invoked by uid 500); 5 Oct 2011 07:30:40 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 75249 invoked by uid 99); 5 Oct 2011 07:30:40 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Oct 2011 07:30:40 +0000 X-ASF-Spam-Status: No, hits=2.6 required=5.0 tests=FREEMAIL_FROM,FROM_LOCAL_NOVOWEL,HK_RANDOM_ENVFROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of cgsmcmlxxv@gmail.com designates 209.85.220.180 as permitted sender) Received: from [209.85.220.180] (HELO mail-vx0-f180.google.com) (209.85.220.180) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Oct 2011 07:30:34 +0000 Received: by vcbf11 with SMTP id f11so1665694vcb.11 for ; Wed, 05 Oct 2011 00:30:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=eOap4sVdlsZUahbi4j7RKt+skSSpTDq4j3Dod0cxYdo=; b=qNd8utyM081f3cZ9haT0TgU1U8hzT4zJnIb0zC+OJAzotr0/b+tqDhOZQdY0NmZPNH X2+QiwnUq2W7oOowXhTgGGr9BOVNZDFMz1Mcf8DYXTybLtaI47nUiuBWCCSI6h5jc0FV cy/BZvjnsXZ32iiOygZwepNQ8Bs71exDMdwZ8= MIME-Version: 1.0 Received: by 10.52.180.101 with SMTP id dn5mr2081900vdc.458.1317799813760; Wed, 05 Oct 2011 00:30:13 -0700 (PDT) Received: by 10.52.166.227 with HTTP; Wed, 5 Oct 2011 00:30:13 -0700 (PDT) In-Reply-To: References: Date: Wed, 5 Oct 2011 10:30:13 +0300 Message-ID: Subject: Re: Help with Erlang views From: CGS To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=bcaec51a7ff8c8c83204ae882d73 X-Virus-Checked: Checked by ClamAV on apache.org --bcaec51a7ff8c8c83204ae882d73 Content-Type: text/plain; charset=ISO-8859-1 -module(put_your_module_name_here). -export([parse_date/1]). parse_date(TZ) -> {{Y,Mo,D},{H,M,S}} = erlang:localtime(); io_lib:format("~p/~p/~p ~p:~p:~p+~s",[Y,Mo,D,H,M,S,TZ]). This should return a string of your choice, considering the local time (that from your computing element where you run this code) when the function parse_date was accessed. TZ has to be a string of form "xyzw" which is passed to the function. I hope this will help you to solve your problems. Cheers, CGS On Wed, Oct 5, 2011 at 7:32 AM, kowsik wrote: > Was chatting with @jchris about erlang views and would love to get > some help on this. On blitz.io we are in the process of investigating, > experimenting with Erlang views. Purely from an operational > perspective, we are not trying to become Erlang hackers. Just need to > know enough to be dangerous and make our CouchDB clusters fly and > scale out. :) > > We are already using the built-in reduce functions and I as looked > through all of our design views, they mostly fall into the following > two buckets. I'm suspecting most other users' map functions fall into > this category. > > function(doc) { > if (doc.type === "foo" and doc.foo) { > emit(Date.parse(doc.created_at), null); > } > } > > @jchris pointed me to this https://github.com/daleharvey/dh_date but > would be awesome to see this part of utils:date_parse or date:parse as > a built-in function that can handle both strftime("%Y/%m/%d %H:%M:%S > +0000") as well as iso8601. This is a fairly common use case for us. > > Next one is this: > > function(doc) { > if (doc.type === "foo" && doc.foo) { > for (i in doc.foo) { > if (doc.hasOwnProperty(i)) { > emit(doc.foo[i], null); > } > } > } > } > > Pretty much everything we have falls into using Date.parse or > iterating over an array/object to emit a bunch of KVs. Can someone > help translate this to Erlang please? I have googled around and seen a > few examples. The latter has some online examples using list:foreach, > but Date.parse didn't seem to have any. > > Thanks and much appreciated, > > K. > --- > http://blog.mudynamics.com > http://blitz.io > @pcapr > --bcaec51a7ff8c8c83204ae882d73--