Set a minimum and maximum date in a calendar component flash cs6 - actionscript-3

I am trying to customize a date picker to be used in an application, that based on what type of person they are they are limited to a specific date range in the calendar. for example if they were type1 they would be able to select 30 days from the current date and all days before that would be grayed out and all days past the 30 would be grayed out as well. I have searched Google and not come up with anything so any help would be so appreciated.
Thanks

I'm going to assume you're using a mx DateChooser component, I'm not familiar with the calendar component in Flash CS6. Either way I'm sure the code is quite similar.
You can supply a disable date range to the DateChooser component
<mx:DateChooser id="myDate" />
All you need to do is get the current date, subtract 30 days and set that as the range end.
var d:Date = new Date(); //current date
d.date -= 30; //-30 days, yup- its that easy
myDate.disabledRanges = [ {rangeEnd:d} ] //disabledRanges takes an array of objects
//with rangeStart and rangeEnd
//you don't need a start date since you want to disable all dates before 30 days ago.
Hope this helps

Related

EOMONTH equivalent in Google Scripts

I'm writing a script that doing some date manipulation and I need to know how many days between current date and end of the month.
I've already got a function that I can put two dates into and it'll return the number of days between the two dates.
I'm looking for an equivalent of EOMONTH in scripts so I can return the date of the last day of any given month
(Hope that makes sense)
All I've been able to come up with so far is adding a day to the date until it becomes a new month and running a counter whilst doing so, but this just seems a really silly way of doing it.
function daysInMonth(m=0) {
return new Date(new Date().getFullYear(),m+1,0).getDate();
}

How do I tell google sheets to only make a calculation after a certain time period?

Context
So I am currently building a database of data for financial assets to conduct some machine learning from to build trading signals. I am trying to calculate the geometric mean but over a given period (monthly). I want to tell google sheets to only calculate the geometric mean after every month. I tried using this formula to no avail:
=IF(last date of the month - first date of month = total days in a month,
GEOMEAN(filter(abs(range),abs(range)>0)),""))
** There were values in the last date of the month - first date of month = total days in a month **
It ended up doing it for every day for the 10 year data set.
** Update
This is the data:
Date Close Cleaned Data Returns Gross returns Geometric average returns
13/11/2015 280 -0.0267 0 1
16/11/2015 280 -0.0267 0 1
17/11/2015 280 -0.0267 0 1
...
23/12/2016 296.4 0.0236 -0.1561348935 0.8438651065
28/12/2016 295.2 0.0199 -0.0770931339 0.9229068661
29/12/2016 294.7 0.0183 0.03341318035 1.03341318
30/12/2016 294.9 0.0190 0.3718276303 1.37182763
Problem (UPDATE)
How do I create a function to let google sheet do calculations only for the last day of every month for a given time series data? Say within this time period, (1 year) I want to calculate the geometric mean for each month in this period and for new data I might want to add later in the future.
To do this you will have to set a trigger event. This is found within the script editor under the edit tab, second to last option.
Image of where to find the trigger manager: It's in spanish, but it will be found in the same place
Once there, click on add trigger, which will be found on the bottom right corner. The first option will ask you which function do you want to run from the bound script. Then select the source of the event and select according to time (My platform is in spanish so I'm trasnlating it you might have it written differently). Then it will prompt you: if you want it to be at an exact date and time, every minute, every hour, day, week and month. Select month and select the day of the month you want the trigger to happen in the next prompt and select the time for the last prompt, then click save.
Finding the last day of a month:
function lastdayOfMonths() {
let html='';
let td=new Date();
for(var i=0;i<12;i++) {
let dt=new Date(td.getFullYear(),td.getMonth()+i+1,0);
let dts=Utilities.formatDate(dt, Session.getScriptTimeZone(),"E MMM dd,yyyy");
html+=Utilities.formatString('<br />%s',dts);
}
SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html), "Last Days of Months for next year");
}

Converting timer format hh:mm to decimal format hh.decimal(mm) in Business Objects

The aim is to create a new data column based on a current time formatted colum.
For example I want to have 4:20 -> 4.33. I can't find a way of manipulating the time format to extract the hours and minutes seperatly to use hours + (minutes / 60).
Any help appreciated. Thank you.
To pick specific parts out of a datetime object you need to use the FormatDate() function. It returns a string which you need to convert to a number with the ToNumber() function before adding the hours and minutes together. So let's create a few variables...
Current DateTime=CurrentDate()
Hours=ToNumber(FormatDate([Current DateTime];"hh"); "##")
Minutes=ToNumber(FormatDate([Current DateTime];"mm"); "##")
Hours Minutes Decimal=[Hours] + ([Minutes]/60)
If you want to put this all together in one variable you can certainly do that...
Hours Minutes Decimal All in One=ToNumber(FormatDate(CurrentDate();"hh"); "##") + (ToNumber(FormatDate(CurrentDate();"mm"); "##")/60)
To locate documentation on what values correspond to which parts of the datetime value do the following...
Navigate to the FormatDate() function in the Variable Editor.
Click on "More on this function" in the lower right corner.
Click on "Custom Formats"

Google Forms createResponse with date decrements the day by 1

I am programmatically generating new form responses from rows of data in a Google Sheet (one approval workflow system generates new approval requests in a second approval workflow system). The data includes dates. My script takes the date value as a string from a cell, converts it into a native JavaScript date object, then submits this to a new form response using createResponse(). Here's the pertinent code:
var startDate = googleFormsDateStringToDate(eventDetails['Event Start Date']);
var r = item.createResponse(startDate);
For the most part, the system works robustly. Except for one intriguing problem - for any date after 29/04/2020, the date stored in the response is decremented by 1 day. Any date on or before this date works as expected, any date after is decremented by a day.
I have tried a few things.
The dates correspond to a start date and end date for an event. If the start date is before this date and the end date after, the end date will be decremented whilst the start date is recorded accurately. So I am certain the issue is directly related to whether the date I am submitting falls before or after this date.
I have tested extensively and am absolutely certain that the string-date conversion is working. If I retrieve the value of the response immediately after creating it (before the form response is even submitted), I find that it has been decremented:
var startDate = dateStringToDate(eventDetails['Event Start Date']);
Logger.log(startDate.toString()); // startDate is always accurate
var r = item.createResponse(startDate);
Logger.log(r.getResponse()); // if after 29/04/2020, will be decremented by 1 day
This tells me the issue is occurring precisely when I create the response and that it is occurring "at Google's end".
One of my suspicions is that it may be a timezone issue, but that would not explain why the issue is linked directly to this specific date. My other suspicion is that it may be to do with the fact that 2020 is a leap year, so we get 29/02/2020, and the date after which the error occurs is 29/03/2020. Perhaps somewhere behind Google's implementation of createResponse it is failing to account for the leap year?
Until I can identify the error, I plan to implement a workaround in which I will use getResponse() to check if the response date matches the intended date and correct accordingly. But I would prefer to understand what is causing the error (so I know if it is a bug requiring reporting, or simply my lack of understanding) and, if possible, find a solution.
So, specific questions: What is the source of the error? Is there a solution (rather than a workaround)?
EDIT
Whilst figuring out a workaround, I have answered my first question. In the UK, daylight savings time starts on 29/04/2020. Since the dates entered via the Google Form have no time associated with them, the time appears to be stored as 00:00:00, or midnight. I assume that what is happening is that the adjustment for daylight savings time (1 hour) is subtracting an hour from this time, thereby rolling it back to the day before.
My final question stands: is there a means to reliably prevent this error from occurring rather than manually checking for inaccurate dates (or programming in daylight savings time dates)?

Flex calendar minimum date & age validation

I'm wiring up a flex registration form, and need to setup a minimum age for registration of a new user of 16 years old. I see the flex calendar component has the option for date ranges and minimum year, but I didn't readily see anything in the attributes for setting a required parameter for selected to be at least 16 years prior to today's date.
What is a good way to setup a calendar validation condition for D.O.B. required to be at least 16 years prior to today?
"flex calendar" - custom component or "DateChooser" ?
you can calculate dates via pure AS3 like:
get current date -> then set the component range(s) or just compare current date - selected date :)
What is the best way to calculate Age using Flex?