Proper way to check for null dates in Flex/Actionscript?

ε祈祈猫儿з 提交于 2019-12-12 01:58:58

问题


When working with Date() objects in Flex/Actionscript, I'm using to following function to check for null dates. Is this the proper way to check for a null date or is there a better alternative out there?

public function IsDateNull(date:Date):Boolean
{
  if (date && date.fullYear != 0)
  {
    return true;
  }

  return false;
}

回答1:


Since Date is a class that extends Object and isn't a primitive type it doesn't have a default value and therefore should only be null if it hasn't yet been instantiated. Is the Date being populated from some sort of database mapping or something along those lines? otherwise not just

if(!date)

or

if(date==null)

no need to have a function to do this. For the DateField.selectedDate the value should be null if no date has been selected yet. This wasn't originally posted as an answer because I don't entirely understand the issue being encountered it sounds as though there's a variety of cases though. Depending on the service layer and underlying JDBC (or other connector) to the DB and the type of DB and datatype the values can vary. In general a Date will be null until memory is acquired for it through a call to the constructor though.

Thanks, Shaun



来源:https://stackoverflow.com/questions/5171646/proper-way-to-check-for-null-dates-in-flex-actionscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!