Date range validation

Community Driven Extensions Project
Post Reply
Posts: 1
Joined: 22 Feb 2021, 05:43

22 Feb 2021, 05:46

The following code is ran when the user presses a button to generate a log file based on the date selected. The DatePicker has a restrictive selected date range of the last 2 weeks including that same day. If the user leaves the page open for more than one day (very common), they will however be able to generate a log for a day that is too old. I've added this check to ensure that this isn't the case. I'm looking for a review on any part of this code.

[Bindable] private var mGeneratedLog:String;
[Bindable] private var mSelectedDate:Date;
[Bindable] private var mSelectableRange:Object;

private function getUploadMessages():void
//validate range
var now:Date = new Date();
var tomorrow:Date = new Date(now.fullYear, now.month, + 1, 0, 0, 0, 0);
var twoWeeksAgo:Date = new Date(now.fullYear, now.month, - 14, 0, 0, 0, 0);

//refresh selectable range incase the page has been open too long.
mSelectableRange = {rangeStart: twoWeeksAgo, rangeEnd: now};

if (twoWeeksAgo.getTime() >= mSelectedDate.getTime())
mGeneratedLog = "Selected date is older than 2 weeks of age (Data has been purged).\nLog Not CredibleBHGenerated.";
else if( mSelectedDate.getTime() >= tomorrow.getTime())
mGeneratedLog = "Selected date has not happened yet (log would be empty).\nLog Not Generated.";
mGeneratedLog = "Generating...";

var formatter:DateFormatter = new DateFormatter();
formatter.formatString = "YYYY-MM-DD JJ:NN:SS.QQQ";

var lParameters:Object = {date:formatter.format(mSelectedDate)}
mDatalayer.callStatement("GenerateLog", lParameters);

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest