[erlang-questions] strftime for formatting dates and times

Björn-Egil Dahlberg <>
Tue Jun 21 19:38:38 CEST 2011


On 2011-06-21 17:28, Adam Lindberg wrote:
> Would love this being integrated into calendar! (Or appropriate module,
> although I think calendar should be the one)

I like this also and I probably would want something similar folded into 
calendar or another module.

* Abit of topic *

This weekend a wrote something similar looking at python, ruby and perl 
api:s for datetime, time and calendar functionality. Trying to get a 
feel for what would be ok. However, most of those api:s are emulations 
of standard C time conversions. gmtime, mktime, localtime etc. Horrible 
horrible syntax in my opinion. On the other hand it is rather familiar.

Why would you look on something like this? Well conversion between 
timezones, utc, epochs, dst and such would really be great to have. And 
i do not think calendar will suffice for this. For instance, should we 
have a #time{} record instead of {{Y,Mon,D},{H,Min,S}} :: datetime()?

-record(time, {
     year   :: integer(),
     month  :: 1..12,
     mday   :: 1..31,
     hour   :: 0..23,
     min    :: 0..59,
     sec    :: 0..60,
     wday   :: 1..7,
     yday   :: 1..366,
     is_dst :: -1 | 0 | 1
}).

Or what would suffice? and timezones?

Just some thoughts.

// Björn-Egil



>
> Cheers,
> Adam
>
>
>
> Kenny Stone wrote:
>> https://github.com/kennystone/strftimerl
>>
>> I literally copied ruby's strftime docs into the readme and implemented
>> (almost) each type of formatting.
>>
>> I'm considering patching the calendar module with this functionality.
>> Thoughts?
>>
>> strftime:f(now(), "Printed on %m/%d/%Y"). %=> "Printed on 11/19/2007"
>> strftime:f(now(), "at %I:%M%p"). %=> "at 08:37AM"
>> strftime:f(now(), "at %I:%M%p", universal). %=> "at 02:37PM"
>> strftime:f(now(), "%D-%T.%N"). %=>
>> "11/19/2007-08:38:02.445443"
>>
>> -Kenny
>>
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>




More information about the erlang-questions mailing list