Can't define methods on a @datetime class

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Can't define methods on a @datetime class

apjanke-floss
Hi, Octave maintainers,

I'm working on an experimental implementation of the @datetime class.

I have a basic class that defines properties and basic conversions:
https://github.com/apjanke/octave-addons/blob/968429c90ac25a422dec70bdd3c25811faba92ce/Mcode/datetime.m

I'm able to construct @datetime objects. And I can access its properties
to verify it was constructed correctly.
But I'm not able to call any methods on them. Octave is not recognizing
that they're defined.

For example, I've defined a custom disp() for it, but the output remains
the default "<object datetime>". And I
have a datestr() method, but attempting to call it looks like it's
calling the default datestr function. I have a hello()
method, and that seems to work, so it's at least picking up some of the
definitions. But "methods(d)" reports
no methods.

Could Octave's built-in "unimplemented" placeholder function for
datetime be interfering with my ability to define
a class named "datetime"?

Example:

octave:1> cd ~/local/repos/octave-addons/Mcode; addpath
~/local/repos/octave-addons/Mcode
octave:2> d = datetime('now')
d =
<object datetime>

octave:3> d.dnums
ans =  737437.0985309570
octave:4> datestr(d.dnums)
ans = 12-Jan-2019 02:21:53
octave:5> datestr(d)
error: floor: not defined for object
error: called from
     datevec at line 161 column 7
     datestr at line 181 column 7
octave:5> hello(d)
ans = Hello, world!
octave:6> methods(d)
Methods for class datetime:


octave:7> class(d)
ans = datetime
octave:8> which datetime
'datetime' is a built-in function
octave:9>


Cheers,
Andrew

Reply | Threaded
Open this post in threaded view
|

Re: Can't define methods on a @datetime class

Andreas Weber-6
Am 12.01.19 um 08:23 schrieb Andrew Janke:
> I have a basic class that defines properties and basic conversions:
> https://github.com/apjanke/octave-addons/blob/968429c90ac25a422dec70bdd3c25811faba92ce/Mcode/datetime.m 

As far as I can see there is a end in line 96 for the switch.
Tehn display and disp are defined which causes, that they are inside
function datetime

If I fix the end and remove isnan because it is implemented twice disp
is called as expected.

HTH, Andy

Reply | Threaded
Open this post in threaded view
|

Re: Can't define methods on a @datetime class

apjanke-floss


On 1/12/19 4:11 AM, Andreas Weber wrote:

> Am 12.01.19 um 08:23 schrieb Andrew Janke:
>> I have a basic class that defines properties and basic conversions:
>> https://github.com/apjanke/octave-addons/blob/968429c90ac25a422dec70bdd3c25811faba92ce/Mcode/datetime.m 
>
>
> As far as I can see there is a end in line 96 for the switch.
> Tehn display and disp are defined which causes, that they are inside
> function datetime
>
> If I fix the end and remove isnan because it is implemented twice disp
> is called as expected.
>
> HTH, Andy
>

Bingo. Thank you!

Cheers,
Andrew

Reply | Threaded
Open this post in threaded view
|

Re: Can't define methods on a @datetime class

Andreas Weber-6
Am 12.01.19 um 10:37 schrieb Andrew Janke:

> On 1/12/19 4:11 AM, Andreas Weber wrote:
>> Am 12.01.19 um 08:23 schrieb Andrew Janke:
>>> I have a basic class that defines properties and basic conversions:
>>> https://github.com/apjanke/octave-addons/blob/968429c90ac25a422dec70bdd3c25811faba92ce/Mcode/datetime.m 
>>
>>
>>
>> As far as I can see there is a end in line 96 for the switch.
>> Tehn display and disp are defined which causes, that they are inside
>> function datetime
>>
>> If I fix the end and remove isnan because it is implemented twice disp
>> is called as expected.
>>
>
> Bingo. Thank you!

You're welcome, glad to help. If you plan to implement datetime for
Octave I would suggest to use to use endfunction, endswitch,
endproperties, endmethods and so on for better readability.

-- Andy

Reply | Threaded
Open this post in threaded view
|

Re: Can't define methods on a @datetime class

apjanke-floss


On 1/12/19 4:52 AM, Andreas Weber wrote:

> Am 12.01.19 um 10:37 schrieb Andrew Janke:
>> On 1/12/19 4:11 AM, Andreas Weber wrote:
>>> Am 12.01.19 um 08:23 schrieb Andrew Janke:
>>>> I have a basic class that defines properties and basic conversions:
>>>> https://github.com/apjanke/octave-addons/blob/968429c90ac25a422dec70bdd3c25811faba92ce/Mcode/datetime.m 
>>>
>>>
>>>
>>>
>>> As far as I can see there is a end in line 96 for the switch.
>>> Tehn display and disp are defined which causes, that they are inside
>>> function datetime
>>>
>>> If I fix the end and remove isnan because it is implemented twice
>>> disp is called as expected.
>>>
>>
>> Bingo. Thank you!
>
> You're welcome, glad to help. If you plan to implement datetime for
> Octave I would suggest to use to use endfunction, endswitch,
> endproperties, endmethods and so on for better readability.
>
> -- Andy

Yep, I'll switch the style over to the GNU Octave style before
submitting it. I'm just not a fan of that style personally, so I'm going
to keep it in Matlab style while it's under development.

Andrew

Reply | Threaded
Open this post in threaded view
|

Re: Can't define methods on a @datetime class

Mike Miller-4
In reply to this post by apjanke-floss
On Sat, Jan 12, 2019 at 02:23:33 -0500, Andrew Janke wrote:
> I'm working on an experimental implementation of the @datetime class.

Care to contribute / collaborate?

  https://gitlab.com/mtmiller/octave-datetime

I only have a stub @datetime so far, but a full set of @duration
operations.

--
mike

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Can't define methods on a @datetime class

apjanke-floss

On 1/12/19 12:08 PM, Mike Miller wrote:

> On Sat, Jan 12, 2019 at 02:23:33 -0500, Andrew Janke wrote:
>> I'm working on an experimental implementation of the @datetime class.
>
> Care to contribute / collaborate?
>
>    https://gitlab.com/mtmiller/octave-datetime
>
> I only have a stub @datetime so far, but a full set of @duration
> operations.
>

Cool. I'll send you a direct email with discussion.

Cheers,
Andrew

Reply | Threaded
Open this post in threaded view
|

Re: Can't define methods on a @datetime class

Andreas Weber-6
In reply to this post by apjanke-floss
Am 12.01.19 um 10:53 schrieb Andrew Janke:
>> You're welcome, glad to help. If you plan to implement datetime for
>> Octave I would suggest to use to use endfunction, endswitch,
>> endproperties, endmethods and so on for better readability.
>>
>> -- Andy
>
> Yep, I'll switch the style over to the GNU Octave style before
> submitting it. I'm just not a fan of that style personally, so I'm going
> to keep it in Matlab style while it's under development.

My point was that you would have found the problematic end yourself (or
at least it would have been easier for me) if you would have used
endswitch, endfunction, endmethods. In my eyes this Octave addition is
not only "style" but a way to increase readability.

-- Andy

PS: I saw you've removed datetime.m from your repo? Why


Reply | Threaded
Open this post in threaded view
|

Re: Can't define methods on a @datetime class

apjanke-floss


On 1/13/19 1:35 PM, Andreas Weber wrote:

> Am 12.01.19 um 10:53 schrieb Andrew Janke:
>>> You're welcome, glad to help. If you plan to implement datetime for
>>> Octave I would suggest to use to use endfunction, endswitch,
>>> endproperties, endmethods and so on for better readability.
>>>
>>> -- Andy
>>
>> Yep, I'll switch the style over to the GNU Octave style before
>> submitting it. I'm just not a fan of that style personally, so I'm
>> going to keep it in Matlab style while it's under development.
>
> My point was that you would have found the problematic end yourself (or
> at least it would have been easier for me) if you would have used
> endswitch, endfunction, endmethods. In my eyes this Octave addition is
> not only "style" but a way to increase readability.
>
> -- Andy
>
> PS: I saw you've removed datetime.m from your repo? Why
>

Fair point. I'm pretty reliant on Matlab's auto-formatting for the same
thing.
I'll consider switching over.

I moved datetime to a separate repo that is now structured as an Octave
pkg project: https://github.com/apjanke/octave-addons-chrono. That'll
make it easier to work with, and make sure dependencies on the other
bits of code (like string/ and misc/) in my main octave-addons don't
creep in to it.

Cheers,
Andrew

Reply | Threaded
Open this post in threaded view
|

Re: Can't define methods on a @datetime class

apjanke-floss


On 1/13/19 4:48 PM, Andrew Janke wrote:

>
>
> On 1/13/19 1:35 PM, Andreas Weber wrote:
>> Am 12.01.19 um 10:53 schrieb Andrew Janke:
>>>> You're welcome, glad to help. If you plan to implement datetime for
>>>> Octave I would suggest to use to use endfunction, endswitch,
>>>> endproperties, endmethods and so on for better readability.
>>>>
>>>> -- Andy
>>>
>>> Yep, I'll switch the style over to the GNU Octave style before
>>> submitting it. I'm just not a fan of that style personally, so I'm
>>> going to keep it in Matlab style while it's under development.
>>
>> My point was that you would have found the problematic end yourself
>> (or at least it would have been easier for me) if you would have used
>> endswitch, endfunction, endmethods. In my eyes this Octave addition is
>> not only "style" but a way to increase readability.
>>
>> -- Andy
>>
>> PS: I saw you've removed datetime.m from your repo? Why
>>
>
> Fair point. I'm pretty reliant on Matlab's auto-formatting for the same
> thing.
> I'll consider switching over.
>
> I moved datetime to a separate repo that is now structured as an Octave
> pkg project: https://github.com/apjanke/octave-addons-chrono. That'll
> make it easier to work with, and make sure dependencies on the other
> bits of code (like string/ and misc/) in my main octave-addons don't
> creep in to it.
>
> Cheers,
> Andrew

For anyone who's interested, I've got basic datetime, duration, and
calendarDuration functionality working, with partial time zone support.
If you'd like to try it out:

https://github.com/apjanke/octave-addons-chrono
https://github.com/apjanke/octave-addons-chrono/releases/tag/v0.1.0

For Octave 4.4.0 and newer:

pkg install
https://github.com/apjanke/octave-addons-chrono/releases/download/v0.1.0/chrono-0.1.0.tar.gz

Cheers,
Andrew