-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 <[email protected]> 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
>