-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor datetime code #673
Comments
You have too little understanding of the infrastructure to tackle any "refactoring" yet. What you call "fragility" comes only from your current (you'll see, eventually) shallowness.
or in #627 (comment):
I often let it pass, to reduce conflict, but it has the deterrent property to mislead others The other types were part of a smooth transition |
Agreed that I personally have not a full understanding of the codebase yet, which is also why I'm not diving into such a refactoring immediately, but I did want to put down my thoughts for them to not get lost and for others to chime in. Anyway, thanks for your thoughts on the datetime issue. Having a drop-in replacement for client code indeed seems like an advantage, but I'm not sure yet how this fits into the bigger picture. |
Currently, the codebase has a distinction between:
hday
or "hamster days", which refer to the day that a fact (start) belongs to. This is mostly the same as the regular day, but for past-midnight times, the hday is one day less than the regular date (i.e. past-midnight times are associated with the preceding day). These hamster days are represented by a customhday
subclass ofdate
.This distinction is sometimes non-obvious, and mixing these leads to problems with past-midnight facts. It would be good to change some variable names to say
day
orhday
to make this more explicit. In particular:CustomFactController.date
refers to the hamster day selected in the edit activity window (i.e. the date shown in the dayline at the top).Fact.date
refers to the hamster day for a given fact.I'm still a bit on the fence on whether to prefer
day
orhday
for these variables. In https://github.com/ederag/hamster/commits/fix-calendar-offset @ederag usedday
to fix 1. above, andday
is also used as part ofdefault_day
in various places. On the other hand, usinghday
looks a bit more specific, which could make it more obvious to casual readers of the code that this is not just a date variable (and grepping the code forhday
would more readily turn up thehday
class). Any thoughts on this?A second distinction that is made is between:
date
,time
anddatetime
objects (referred to aspdt.date
,pdt.time
andpdt.datetime
in some places)I guess the idea is to use the Hamster-specific classes as much as possible, only converting to and from the
pdt
types when talking to external code (i.e. through DBus), so I don't think any variable renames are needed here.I do wonder if the upsides of these extra types is worth the extra complexity (and the fragility from mixing up types). It seems that a large part of the code for these types is to ensure that any operations on the custom code will still return the custom types and handle conversion to and from the standard types (in other words, all that code would not be needed if these types did not exist). Looking at what these types actually add:
pdt.time
totime
, it the deprecatedhamster_round
function suggests this used to be done before), but I guess there is some value in doing this automaticaly.datetime
tohday
. This could just be a matter of adding an appropriate constructor to thehday
class, I guess, or using a global function (this seems to have been the old approach, looking at the deprecateddatetime_to_hamsterday()
function)Note that I think the
hday
type is certainly useful, since that actually changes the meaning of the value, so it is good to track that. but for the other types, I'm not so sure.The text was updated successfully, but these errors were encountered: