Prev | Current Page 227 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

title);
}
}
Usually when a blog entry is created, it is just a draft and not really ready for publication. It is better to
have a publish() method that expressly states when a post is ready to go online and a method
unpublish() , to revert the post to the draft state just in case.
class BlogEntry
{
public var title(default,default) : String;
public var content(default,default) : String;
public var createdOn : Date;
public var onlineInfo(getOnlineInfo,null) : String;
private var publishedOn : Date;
public function new (title : String, content : String)
{
this.title = title;
this.content = content;
createdOn = Date.now();
publishedOn = null;
}
public function publish() : Void
{
publishedOn = Date.now();
}
public function unpublish() : Void
{
publishedOn = null;
}
public function isOnline() : Bool
{
return publishedOn != null
& & publishedOn.getTime() < = Date.now().getTime();
}
(continued)
110
Part I: The Core Language
private function getOnlineInfo() : String
{
if(publishedOn == null)
return ???Not yet on-line???;
else
{
// getTime() returns the time in milliseconds since 1970-01-01
// we have to divide the time span by 24 hours=24*60*60*1000=86400000
var daysOnline = (Date.


Pages:
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239