Flex Date related Functions - apache-flex

I need to calculate a start date as 01- 01- 2013 when my end date is 31-12-2012 using Flex Date Functions'.

I assume you want to add a certain amount of days (1 in your example) to an existing date? You can do this by creating a new date based on the time of the other date + the difference:
Example:
var numMillisecondsInOneDay:Number = 24*60*60*1000;
var startDate:Date = new Date(endDate.getTime() + numMillisecondsInOneDay);
FYI: The AS3Commons-Lang project contains a DateUtils class that offers a set of Date manipulation methods.

Related

Get time format according to spreadsheet locale?

I want to store a Javascript Date() object in a spreadsheet with correct format according to spreadsheet's locale (SpreadsheetApp.getActive().getSpreadsheetLocale()).
Is there a way to get the country specific (date and) time format string from the spreadsheet locale?
E.g. when locale is de_DE, time format string as hh:mm
but when locale is da_DK, time format string as hh.mm
Interesting as well how to get the countries currency format.
BTW when I have date and time in de_DE and than change to da_DK, dates are reformatted (23.01.2020 -> 23/01/2020) but times are not (it stays as 22:59). Is that an error in Spreadsheet?
Dates in JavaScript have the method toLocaleDateString, which return a string formatted according to the specified locale. But this doesn't seem to work in Apps Script.
If you're open to using an Apps Script Web App for this, you could use this toLocaleDateString in your client-side script (that is, in a script tag in your HTML).
If that's not the case, I think your best option would be to create the relationship between formats and locales yourself, because Apps Script doesn't have a built-in method to achieve that. You could, for example, use a switch statement that would check the locale, and then format the date accordingly with Utilities.formatDate, the tool Apps Script uses to format dates. It could be something along the following lines:
var locale = SpreadsheetApp.getActive().getSpreadsheetLocale();
var formattedDate;
switch (locale) {
case 'de_DE':
formattedDate = Utilities.formatDate(yourDate, yourTimeZone, "hh:mm");
break;
case 'da_DK':
formattedDate = Utilities.formatDate(yourDate, yourTimeZone, "hh.mm");
break;
// ...
}
return formattedDate;
Reference:
toLocateDateString
Apps Script Web Apps
Utilities.formatDate
I hope this is of any help.
Sorry for that, however I found a function that would be worth checking out, it's toLocaleDateString() and toLocaleTimeString (), they deliver the local date and time format.
Please check
Formato fechas JavaScript.
I did the test from Google Apps Script and it throws me the following
function pruebafecha() {
var d = new Date();
var n = d.toLocaleDateString();
var h = d.toLocaleTimeString();
Logger.log(n);
Logger.log(h);
}
This is the answer(Colombia):
[20-01-24 16:47:50:286 EST] 24 de enero de 2020
[20-01-24 16:47:50:287 EST] 16:47:50 EST
A JavaScript Date object includes date, time and timezone. When Google Apps Script pass a Date object to the spreadsheet using setValue() / setValues() the value is displayed according to the cell number formatting using the spreadsheet timezone.
If the cell formatting is set to Automatic by default the date will be displayed accordingly to the spreadsheet locale.
If you want to force the cell to display a date in an specific format use Class Range setNumberFormat / setNumberFormats
If you don't want to use the above methods and don't want to rely on the spreadsheet locale and automatic cell format then instead of passing a Date object pass the value as an string prepending it with an ' (apostrophe, single quote character) to prevent that that automatic data type parsing changes the value and it's format.
Related
Javascript in Google Sheets script: help using setNumberFormat
I don't know very well the configuration of the sheet you mention. However, I share a code that I use to print the date and time of data submission of a form.
var d = new Date();
var hour = d.getHours()-1;
var min = d.getMinutes();
var day = d.getDate();
var month = d.getMonth()+1;
var year = d.getFullYear();
if (month<10) {dia = day+"/"+"0"+month+"/"+year;}
else {dia = day+"/"+month+"/"+year;}
if (min<10){time = hour+":"+"0"+min;}
else {time = hour+":"+min;}
What I do in the code is to take the values ​​of day, month and year, I add 1 to the value of month because it takes values ​​[0:11] => [Jan, Dec].
Then I build the format I want from date and time, you can notice that I have 1 left to the hours, because when I did the tests I noticed that the time of the script was one hour above.
I use google translate, I hope it is understood.

How to customize the TemporalAdjusters in Java 8?

I am working with Java 8 Date and Time utility. I am using the TemporalAdjuster interface and the implementations found in TemporalAdjusters to manipulate the calculations for a specific day or date.
My requirement is to calculate the day after 3 month and 2 days.
For example, today is 6th of Decemeber (i.e 2016-12-06 in YYYY-MM-DD) and after 3 months and 2 days, the date would be 8th of March, 2017 (i.e. 2017-03-08 in YYYY-MM-DD).
I tried two ways of doing this using the Date and Time utility as follows:
//First
LocalDate dayAfter3MonthsAnd2Days = LocalDate
.now()
.with(firstDayOfNextMonth()).plusMonths(2).plusDays(2);
//Second
LocalDate dayAfter3MonthsAnd2Days = LocalDate
.now()
.with(firstDayOfMonth()).plusMonths(3).plusDays(2);
Both of them returns the date as 3rd of March, 2017 (i.e. 2017-03-03) as follows:
dayAfter3MonthsAnd2Days = 2017-03-03
Is there any way i can customize the TemporalAdjusters and get the desired output? Or any other alternate to achieve the goal?
I found out that i can simply use the following:
LocalDate dayAfter3MonthsAnd2DaysNew = LocalDate
.now()
.plusMonths(3)
.plusDays(2);
Alongwith that, i can also use the custom TemporalAdjuster which uses the above same process to do manipulations as follows:
TemporalAdjuster ta = TemporalAdjusters.ofDateAdjuster(
(LocalDate d) -> d.plusMonths(3).plusDays(2));
LocalDate dayAfter3MonthsAnd2DaysCustom = LocalDate
.now()
.with(ta);
Although the previous way is simpler, but we can use more custom proceedings using ofDateAdjuster method of TemporalAdjuster.

Sage CRM - How to save a date with using the object returned from CRM.FindRecord()

Given this code:
var ToDateDate = new String(Request.Form("Comm_ToDateTime"));
ToDateDate = ToDateDate.split("/");
var newToDateTime = ToDateDate[2]+"-"+ToDateDate[1]+"-"+ToDateDate[0]+" "+Request.Form("Comm_ToDateTime_TIME")+":00.000";
CurrentCommunication("Comm_ToDateTime") = newToDateTime;
CurrentCommunication.SaveChanges();
How can i save the date?
This way the date (as Days, month and year) got saved but the hours, minutos does not.
The final output for the newToDateTime variable is 2016-19-09 08:50:00.000
if i use this value (2016-19-09 08:50:00.000) in a barehand SQL update, it works
Turns out that i have to build the Date object with the values and then use getVarDate() mehtod to to pass from a Date Javascriopt object to a record’s date field value which at the end it is the same i was doing :S
Found my answer in this Sage CRM Community

Does Joda-Time `DateTime` class have methods such as setHours()/setMinutes() as is available in Javascript Date object

I would like to set hours/minutes/seconds manually in DateTime class from Joda-Time library. What I am trying to do is keep year/month/day value but discard hours/minutes/seconds from date object.
DateTime today = new DateTime();
today.??? (method to call set hours/minutes/seconds to 0)
Happy new year to all!
Immutable Objects
Joda-Time uses immutable objects by default. Rather than call a setter method to change (“mutate”) a member variable, we call a method to generate a new instance based largely on the original.
withTime
To create a new DateTime with a certain time-of-day, call the withTime method.
DateTime now = DateTime.now( DateTimeZone.forID( "America/Montreal" ) );
DateTime lunchtimeToday = now.withTime( 12, 30, 0, 0 ); // Half-past noon.
First Moment Of The Day
If you want midnight (first moment of the day), call withTimeAtStartOfDay. Usually this is 00:00:00.000 but not always.
DateTime todayStart = DateTime.now( DateTimeZone.forID( "America/Montreal" ) ).withTimeAtStartOfDay();
Time Zone Is Crucial
Note that time zone is crucial to determining when a day starts. 'Today' in Paris starts sooner than it does in Montréal.
If you omit the time zone, your JVM’s current default time zone will be applied automatically. Better to specify than rely implicitly on this default.
Use proper time zone names. Avoid the 3 or 4 letter codes that are neither standardized not unique.

How to save the Date as DD/MM/YYYY format in SQLITE Flex AIR application

i am doing a flex Adobe AIR Application with SQLITE Data base,in that i want to save Date in the following format DD/MM/YYYY, but in my SQLITE TABLE i gave the data type is DATE so it saved as Sun Dec 2 00:00:00 GMT+0530 2012 in this format.
why i want to save in specific format.i have two date fields START DATE and END DATE.Once i select the End DATE date field i have to count the days between them automatically.any ideas for DD/MM/YYYY format and counting the date in between the dates.
This is my code:
[Bindable] private var date1:Date;
[Bindable] private var date2:Date;
[Bindable] private var Totaldays:String;
protected function modEndDate_creationCompleteHandler(event:FlexEvent):void
{
formatter.formatString= "DD-MM-YYYY";
date1=formatter.format(newStartdate.selectedDate);
date2=formatter.format(newEndDate.selectedDate);
**Totaldays=Math.floor(Math.abs(date1 - date2)/ (24 * 60 * 60 * 1000))**
}
The error is:
Multiple markers at this line:
-1067: Implicit coercion of a value of type Date to an unrelated type Number.
-1067: Implicit coercion of a value of type Number to an unrelated type String.
Looking for help.Thanks in Advance
Regards,
Venkatesan
Save in compatible format. Format dates in GUI as you like. Look here to calculate days between: ActionScript 3.0 + Calculate timespan between two dates?

Resources