Nullable Dates

From AbleCommerce Wiki
Jump to: navigation, search

In AbleCommerce 7.0.0 through AbleCommerce 7.0.7, many of our objects had DateTime properties that were nullable in the database. In these versions we would translate null into the value System.DateTime.MinValue when reading the records. When making business logic decisions the DateTime property would need to be checked against DateTime.MinValue to see if it was present.

In AbleCommerce Gold the behavior changes slightly. Instead of translating null dates, our DateTime properties are nullable. This means the property can either be null or it can have a value. In order to use these DateTime properties you must be sure to factor in the possibility that the value does not exist in the database. In these cases you must decide how to handle that condition.

A list of the properties that are nullable are below:

CLASS PROPERTY SIGNIFICANCE OF NULL
Coupon StartDate The coupon has no restriction on when it starts to be valid.
Coupon EndDate The coupon has no restriction on when it ceases to be valid.
EmailList LastSendDate The email list has never been sent.
EmailListUser LastSendDate The email list has never been sent to this list member.
OrderItemDigitalGood ActivationDate The digital good has not been activated.
OrderItemDigitalGood DownloadDate The digital good has not been downloaded.
OrderShipment ShipDate The order shipment has not been shipped.
Subscription ExpirationDate The subscription has no expiration.
Payment CompletedDate The payment has not yet been completed.
Special StartDate The special has no restriction on when it starts to be active.
Special EndDate The special has no restriction on when it ceases to be active.
Redirect LastVisitedDate The redirect has never been visited.
Currency LastUpdate The exchange rate for the currency has never been updated.
User AffiliateReferralDate The user has not been referred by an affiliate.
User LastActivityDate The user has never browsed the site.
User LastLoginDate The user has never logged in.
User LastPasswordChangedDate The user has never changed the password.
User LastLockoutDate The user has never been locked out.

Working with Nullable Dates

In customizing code with these properties you may notice from Intellisense that nullable dates act a little different from regular DateTime values. There are two different ways to decide if a DateTime has a value:

if (Coupon.StartDate.HasValue)

OR

if (Coupon.StartDate != null)

And when accessing the DateTime you need to use the Value property:

Coupon.StartDate.Value