i am working on script which creates events in Google Calendar from data in SpreadSheet. Following code creates events
in default calendar.
function myFunction() {
cal = CalendarApp.getDefaultCalendar();
cal.createEvent(
'Single day',
new Date("October 25, 2011 15:00:00 EST"),
new Date("October 25, 2011 16:00:00 EST"),
{}
);
cal.createAllDayEvent('All day', new Date("October 25, 2011"), {});
}
The problem is, it creates the events at wrong timing. The all day event is created OK of course
I guess i am supposed to use another timezone code, but when i use CET it creates the event in the begining of epoch
function myFunction() {
cal = CalendarApp.getDefaultCalendar();
cal.createEvent(
'Single day',
new Date("October 25, 2011 15:00:00 CET"),
new Date("October 25, 2011 16:00:00 CET"),
{}
);
cal.createAllDayEvent('All day', new Date("October 25, 2011"), {});
}
And again all day event is OK, becouse i don't use any time zone code.
Format of Date contructor i found here http://code.google.com/intl/cs-CZ/googleapps/appsscript/class_calendar.html#createEvent
So my question is what's the correct code for Central European Time ? Better could be reference for page with these codes.
CET is the correct abbreviation for Central European Time.
It sounds like you found a bug, please file it on the Apps Script Issue Tracker.
Best,
Anton
Related
I was creating project in Angular and to format date I decided to use moment.js. But the problem is from the backend I get such format "2020-02-06" thus I decided to use 'MMM DD, YYYY' and I want "2020-02-06" to look like Feb 6, 2020 with this format MMM DD, YYYY. So, to achieve that I have this code
moment(
response.data.projectCreatedDate //this contains "2020-02-06"
).format("MMM DD, YYYY");
BUT the problem is instead of getting Feb 6, 2020 I get 13 May, 2020 which is today's date. Pls can you help, what am I doing wrong?
Moment with empty argument returns current date, and format on top of it returns current formatted date .Your date from server might be undefined, Hence you are the getting current date formatted.
You can also pass custom date for formatting too!
//Formatting an input date
var str = "2020-02-06";
console.log(moment(str, "YYYY-MM-DD").format("MMM D,YYYY"));
//Formatting current date
console.log('Current Date: ', moment().format("MMM D,YYYY"));
//Formatting array of dates
var arr = ["2020-02-06", "2020-01-13"];
var res = arr.map(date => {
return moment(date, "YYYY-MM-DD").format("MMM D,YYYY");
});
console.log(res);
<script src="https://momentjs.com/downloads/moment.js"></script>
Nothing is wrong with moment here, you are getting an empty response inside response.data.projectCreatedDate from your server.
moment("2020-02-06").format("MMM DD, YYYY") //Feb 06, 2020
moment().format("MMM DD, YYYY") //todays date.
Thanks.
Is there a way to check if an epoch is ambiguous or not in momentjs?
In America/Chicago zone, 2011-11-06 00:00 is not ambiguous but 2011-11-06 01:00 can be either Central Daylight Time (CDT) or Savings Time (CST).
I think something like this will work:
function hasAmbiguousWallTime(m) {
var t = [60, -60, 30, -30];
var a = t.map(function(x) { return moment(m).add(x, 'm').format('HH:mm'); });
return a.indexOf(m.format('HH:mm')) > -1;
}
Examples:
hasAmbiguousWallTime(moment.tz("2011-11-06 01:00", "America/Chicago")) // true
hasAmbiguousWallTime(moment.tz("2011-11-06 00:00", "America/Chicago")) // false
Note that this might fail for transitions that are not either 30 or 60 minutes change in offset, which have occurred historically. A better implementation would test the known transition points in the moment-timezone data, or scan for them against a locally derived moment. That said, the above is sufficient for most modern usage.
When I'm trying to create table or chart on Ui Service using Date objects, it seems that dates are displayed in a timezone which is not the one that is currently configured in the script.
Here is a little example:
function doGet() {
var dateObject = new Date ( "January 1, 2013 12:00:00" );
Logger.log(dateObject);
var dataTable = Charts.newDataTable()
.addColumn(Charts.ColumnType.DATE, 'DateColumn')
.addRow([dateObject])
.build();
var tableChart = Charts.newTableChart()
.setDataTable(dataTable)
.build();
var uiApp = UiApp.createApplication();
uiApp.add(tableChart);
return uiApp;
}
When I launch the script as a webApp, I get this output:
DateColumn
1 janv. 2013 03:00:00
The hour is not correct but when I look into the log, it's fine:
[13-06-23 00:40:30:330 CEST] Tue Jan 01 12:00:00 GMT+01:00 2013
Is there a way to configure how the date will be displayed on the webapp?
Summer dates in an input control which are before 1981 are recalculated (I think with daylight saving time).
e.g.
e.g. I enter 27.8.1960 - after a save I got 26.8.1960, (after the next save 25.8.1960 and so on)
but 27.8.2010 - after a save it stayed the same: 27.8.2010
"Winter dates": 27.4.1960 - after a save it stayed the same: 27.4.1960
looks like an ugly bug. how can I supress this "calculation"?
(date format is Europeen, I live in Germany. 27.8.1960 is August 27, 1960)
thanks for any help, Uwe
<xp:inputText value="#{Auftrag.MF_GebDatum}" id="mF_GebDatum1" style="width:255px">
<xp:this.converter>
<xp:convertDateTime type="date"></xp:convertDateTime>
</xp:this.converter>
</xp:inputText>
The problem you are fighting with is that Domino stores a datetime value with the daylight saving information which does not exists for the dates you are entering. The information for the timezone to use comes from the current user locale and / or the server.
Your date is stored in a field with the timezone it was entered (+2h GMT)
26.08.1960 00:00:00 CEDT
Domino interprets the stored value as it is, without adjusting it
var ndt:NotesDateTime = session.createDateTime("26.08.1960 00:00:00 CEDT");
ndt.getGMTTime()
returns the correct datetime value, adjusted by 2 hours for GMT
25.08.60 22:00:00 GMT
While converted back to Java, it is interpreted "correctly" that there was never a daylight saving time in 1960, that's why it will be adjusted only by 1 hour:
var ndt:NotesDateTime = session.createDateTime("26.08.1960 00:00:00 CEDT");
ndt.toJavaDate().toLocaleString()
will result in "25.08.1960 23:00:00" if you are in the CEDT timezone.
Currently the only idea I have for an easy workaround is to kill the Timezone information in the DateTime field. To do this you can use this SSJS script:
<xp:this.querySaveDocument>
<![CDATA[#{javascript:
var doc:NotesDocument = document1.getDocument( true );
var items:java.util.Vector = doc.getItems();
var item:NotesItem;
var ndt:NotesDateTime;
var dt:java.util.Date;
for( var i=0; i<items.size(); i++){
item = items.get(i);
if( item.getType() === 1024 ){
ndt = item.getValueDateTimeArray().get(0);
ndt = session.createDateTime( ndt.getDateOnly());
item.setDateTimeValue( ndt );
ndt.recycle();
}
item.recycle();
}
}]]>
</xp:this.querySaveDocument>
I want to display to users the time in different cities/timezones like this:
London 2012-02-01 11:30:00 GMT (0)
New York 2012-02-01 06:30:00 GMT (-6)
Stockholm 2012-02-01 12:30:00 GMT (+1)
I need it to be in ssjs and generic so that it does not matter which time zone the server is in.
I have been playing around with the following code lines but can not get it to work
var dt:NotesDateTime = session.createDateTime("Today");
dt.setNow()
//dt.convertToZone(-6,true)
//return dt.getGMTTime()
//return dt.getZoneTime()
GMT is ok, but users timezone is ok as well like GMT,UTC etc..
In this case I would stay away from the NotesDateTime object and use the Java Date object instead. You could do something like:
var d:java.util.Date = new java.util.Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
print(dateFormat.format(d));
dateFormat.setTimeZone(TimeZone.getTimeZone("Europe/London"));
print(dateFormat.format(d));
dateFormat.setTimeZone(TimeZone.getTimeZone("America/New_York"));
print(dateFormat.format(d));
Remember that changing a timezone for a Java Date doesn't change the date itself, it just changes how it is displayed.