Skip to content
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

Add support for using a custom Date class #532

Merged
merged 6 commits into from
Apr 23, 2016

Commits on Apr 1, 2016

  1. Add support for using a custom Date class

    If your project uses a date library that doesn't extend \DateTime (e.g. Zend_Date), then you
    currently have to convert to and from ActiveRecord\DateTime when interacting with models, which is a
    pain and error prone. We've had to fix quite a number of bugs due to missing conversions. This
    commit removes the need for that by adding support for using a custom date class.
    
    The custom class is set in ActiveRecord\Config, which uses similar logic to the logger methods for
    the getter and setter. The ActiveRecord\Config->set_date_class() method checks if the provided class
    has "format" and "createFromFormat" methods, which are all that are required.
    
    I changed everything that created new date objects to use "createFromFormat()" instead of the
    constructor, because many date libraries don't accept a date string in the constructor. Besides, I
    think createFromFormat() is better in general because it's more explicit.
    
    For the "attribute_of" method, I made that an optional feature by introducing an interface that
    defines it, which ActiveRecord\Model->assign_attribute() checks for. The reason I made this optional
    is because if you use an immutable date class (e.g. PHP's DateTimeImmutable), you don't need to
    worry about the dirty flagging, so there's no need to have that method.
    MasonM committed Apr 1, 2016
    Configuration menu
    Copy the full SHA
    03aff58 View commit details
    Browse the repository at this point in the history

Commits on Apr 7, 2016

  1. Configuration menu
    Copy the full SHA
    afb332e View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    637efd1 View commit details
    Browse the repository at this point in the history

Commits on Apr 11, 2016

  1. Configuration menu
    Copy the full SHA
    a5bfee0 View commit details
    Browse the repository at this point in the history
  2. Rename DateTimeLinkedModelInterface -> DateTimeInterface

    As suggested by @koenpunt. I also added createFromFormat() and format() to the interface.
    MasonM committed Apr 11, 2016
    Configuration menu
    Copy the full SHA
    532a394 View commit details
    Browse the repository at this point in the history

Commits on Apr 23, 2016

  1. Configuration menu
    Copy the full SHA
    000cf06 View commit details
    Browse the repository at this point in the history