正确的方法来为您在的Flex /的Actionscript空日期? [英] Proper way to check for null dates in Flex/Actionscript?

查看:186
本文介绍了正确的方法来为您在的Flex /的Actionscript空日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在与日期工作()中的Flex / ActionScript对象,我使用下面的函数来检查空日期。这是正确的方式来检查空日期或是否有更好的选择了吗?

 公共职能IsDateNull(日期:日期):布尔
{
  如果(日期和放大器;&安培;!date.fullYear = 0)
  {
    返回true;
  }

  返回false;
}
 

解决方案

由于日期是一个扩展的对象,而不是一个原始类型它没有一个默认值,因此只应为空,如果它不是招'一类牛逼尚未被实例化。难道日期正从某种数据库映射或类似的规定的填充?否则,不只是

 如果(!为准)
 

 如果(日期== NULL)
 

没有必要有一个函数来做到这一点。对于DateField.selectedDate值应为NULL,如果没有日期已被选中呢。这是不是最初发布作为一个答案,因为我不完全理解所遇到的问题,这听起来好像有各种各样的情况下,虽然。根据不同的业务层和底层的JDBC(或其他连接器)将DB和DB类型上和数据类型的值会有所不同。一般而言,日期为null,直到内存是通过虽然调用构造函数收购了它。

谢谢, 肖恩

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;
}

解决方案

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

这篇关于正确的方法来为您在的Flex /的Actionscript空日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆