daokoder / dao-modules

Dao Standard Modules
http://daovm.net
12 stars 5 forks source link

SIGSEGV in DateTime::format() #76

Open dumblob opened 9 years ago

dumblob commented 9 years ago
dao -e 'load time import time; time.make(2015,9,29).format("%A")'

Btw it might make sense to slightly improve the declaration { TIME_Format2, "format(invar self: DateTime, invar names: map<string,list<string>>, format = '%Y-%M-%D, %H:%I:%S' ) => string" } by using enum: { TIME_Format2, "format(invar self: DateTime, invar names: map<enum<month, week, day, halfday>,list<string>>, format = '%Y-%M-%D, %H:%I:%S' ) => string" }

dumblob commented 9 years ago

Also, the TIME_Format2 doesn't seem to work properly:

0$ dao -e 'load time import time; time.make(2015,9,29).format({ "month" => {"le", "un", "br", "du", "kv", "ce", "cec", "sr", "za", "ri", "li", "pr" }, "week" => {"po", "ut", "st", "ct", "pa", "so", "ne"} }, "%a %b %Y")'
= am  2015
0$ dao -e 'load time import time; time.make(2015,9,29).format({ "month" => {"le", "un", "br", "du", "kv", "ce", "cec", "sr", "za", "ri", "li", "pr" }, "week" => {"po", "ut", "st", "ct", "pa", "so", "ne"} }, "%A %B %Y")'
= AM  2015
Night-walker commented 9 years ago

I would actually either remove the function -- it looks too heavy -- or replace it with something else.

dumblob commented 9 years ago

I would actually either remove the function -- it looks too heavy -- or replace it with something else.

I'm not against under the condition, that the new solution will support arbitrary months, weekdays, yeardays and halfdays labeling.

Night-walker commented 9 years ago

I think it is not required for basic date and time support and is implemented trivially on the user's side.

dumblob commented 9 years ago

I think it is not required for basic date and time support and is implemented trivially on the user's side.

The easiest option is to parse the output of format() (to get the index of day_in_month/day_in_week/day_in_year/halfday_of_day), which is pretty inefficient. Or am I missing something?

Night-walker commented 9 years ago

The easiest option is to parse the output of format() (to get the index of day_in_month/day_in_week/day_in_year/halfday_of_day), which is pretty inefficient. Or am I missing something?

Why, if that info can be fetched directly from the DateTime methods?

dumblob commented 9 years ago

Why, if that info can be fetched directly from the DateTime methods?

Shame on me, I missed weekDay() and yearDay() methods. Writing

listWeekDay[x.weekDay()] + x.format(' %d.') + listYearMonth[x.month] + x.format(' %Y ' + translation['at'].replace('%', '%%') + ' %h:%m:%s')

instead of

x.format('%A %d. %B %Y ' + translation['at'].replace('%', '%%') + ' %h:%m:%s', {$weekday => listWeekDay, $yearmonth => listYearMonth})

is less efficient, but is maybe even slightly more readable than the latter one.

daokoder commented 9 years ago

I would actually either remove the function -- it looks too heavy -- or replace it with something else.

I think it is not required for basic date and time support and is implemented trivially on the user's side.

Agree.