Skip to content

Add DATE support to orbits model #48

@galaGOlol

Description

@galaGOlol

Hi All,
Using orbit to develop a small wiki-type application,
I was given an error whenver I tried to parse something with the DATE field.
It did not have a parser for it. So I edited orbit/model.lua, and basically copied the datetime function.
Here is a diff, if you are interested in adding support for DATE:

98a99,102
> function convert.date(v)
> 	local year, month, day = string.match(v, "(%d+)%-(%d+)%-(%d+)")
> 	return os.time({year=tonumber(year), month=tonumber(month), day=tonumber(day)})
> end
153a158,161
> 
> function escape.date(v)
> 	return "'" .. os.date("%Y-%m-%d", v) .. "'"
> end

I had a few concerns about it.

  1. There is no difference between date and datetime in lua, this could possibly lead to bugs in programs that rely on a time (Since it would be noon, but are only given a date. Hopefully the developer would be aware of that though.
  2. Is it possible to use datetime for date? I tried, but I get the following:
/usr/share/lua/5.1/orbit/model.lua:93: field 'day' missing in date table

This seems to be because of the expression you use to find date. it is (%d+)%-(%d+)%-(%d+) (%d+):(%d+):(%d+)
This means that the day will not be matched for type date, since it does not follow a space. I don't know if you would prefer modifying the expression, or adding a separate function.

Either way, we would want a different function for escape.date.
Is there any reason DATE is not supported? Or is it just waiting for someone to bake support in?

Let me know what you guys think. If you want, I can fork and do a PR, but I don't speak git very well.
Happy new year!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions