I'm using google calendar api v3, for an calendar integration project and I've succeeded in creating calendars, events and even EventReminder. But I'm facing a little issue.
I created an EventReminder using this source code :
Event e = new Event();
int reminderMinutes = 1;
EventReminder reminder = new EventReminder();
reminder.setMinutes(reminderMinutes);
reminder.setMethod("popup");
List<EventReminder> l = new ArrayList<EventReminder>();
l.add(reminder);
e.setReminders(new Reminders().setOverrides(l));
e.getReminders().setUseDefault(false);
And now I am wondering if it is possible somehow to create an EventReminder using days instead of minutes, without converting it into minutes (like 1 day is 1440 minutes).
Thank you for your help.
There is no special method for setting reminder in days, only you could do is using the setMinutes method or what you could do is that you may create a custom method of your own, for converting days into minutes likeint minutes;public int getMinutes(int days){minutes = days * 24 * 60;retutn minutes;}and you may use it as following,
EventReminder reminder = new EventReminder();
reminder.setMinutes(getMinutes(1));
Related
In the Firestore project, I have documents in a collection containing data for shops, having fields like shopName, shopAddress, startTime(eg. 10 AM) and closeTime(eg. 10 PM) . (all strings for now)
When the user is browsing the app, i have retrieved the data from Firestore of the shops displayed in the app, now i wanna show that the shop is closed when the device's time is not between the startTime and closeTime of the shop. How do i achieve this?
So far I can detect the device's current time using dart package intl using this code:
print("${DateFormat('j').format(DateTime.now())}");
It gives output as follows:
I/flutter (14877): 6 PM
This is in DateFormat, and the data types stored in Firestore are strings.. I dont know how to compare them.. Do let me know if i have to change the data types in Firestore too.
Thank You
I think if you use 24 Hour Time Format and convert startTime, closeTime and actualTime to int or double ( if the shop close at 20:30/8:30pm), then you can easily compare them with if. On your firebase server string format is perfect.
For example you make a map and iterate it, and check if the actualTime is higher than startTime and lower than closeTime.
I have never tried this code, but i think it is going to work.
Map map = {'1am': 1, '2am': 2, '3am': 3, ... , '11pm': 23};
map.entries.forEach((e) {
if(e.key == actualTime) {
if(e.value >= startTime && e.value < closeTime) {
print('Open');
}
else{
print('Closed');
}
}
});
By the way, I think you should use UTC, because if you change the time-zone on your device, your app is going to show that the shop is closed, but in fact the shop is open, just you are in a different time-zone. You can easily implement this with this code.
var now = DateTime.now().toUtc();
Maybe you can create a hash map like this:
hashMap=['12 AM', '1 AM', '2 AM', ... , '11 PM', '12 AM'];
After that you can get the positions of startTime, closeTime and actualTime, and see if the actualTime is between start and close times positions.
Let me know if you want to give you a code example.
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.
When I run the ASP project in local host, show correct local time (Sri Lanka) . But when host the project show incorrect date, Time..
lable_date_time.Text = string.Format("{0}", DateTime.Today.ToShortDateString());
Hosting server in United states (www.smarterasp.net)
How to Fix it?
Thank You...
You might find the FindSystemTimeZoneById method useful, along with ConvertTimeFromUtc method. Both are methods of the System.TimeZoneInfo class. Example I used to pass the time in a time zone passed in from a user and converting that to stock market time in NYC. After you do the calculation you can adjust by getting the difference of the offset:
TimeZoneInfo tradeTimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(tradeTimeZone);
var tradetz = TimeZoneInfo.ConvertTimeFromUtc(myexactexetime, tradeTimeZoneInfo);
TimeZoneInfo nyTZI = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
var marketTimezone = TimeZoneInfo.ConvertTimeFromUtc(dateTimeInUsersZone, nyTZI);
TimeSpan diff = marketTimezone - tradetz;
double hours = diff.TotalHours;
dateTimeInUsersZone= dateTimeInUsersZone.AddHours(hours);
I am not able to get any response from youtube analytics v1 API suddenly. It was working fine before.
Code -
string dimension = "country";
string requestedMetrics = "views,redViews,comments,likes,dislikes,videosAddedToPlaylists," +
"videosRemovedFromPlaylists,shares,estimatedMinutesWatched,estimatedRedMinutesWatched," +
"averageViewDuration,averageViewPercentage,cardClickRate,cardTeaserClickRate,cardImpressions," +
"cardTeaserImpressions,cardClicks,cardTeaserClicks,subscribersGained,subscribersLost";
ReportsResource.QueryRequest result = this.analyticsService.Reports
.Query("channel==MINE", this.reportDate.ToString("yyyy-MM-dd"), this.reportDate.ToString("yyyy-MM-dd"), requestedMetrics);
result.Dimensions = dimension;
if (!string.IsNullOrEmpty(videoId) && videoId.ToLower() != "all")
{
result.Filters = $"video=={videoId}";
}
Google.Apis.YouTubeAnalytics.v1.Data.ResultTable resultTable = result.Execute();
The scopes getting used -
string[] scopes = new string[] { YouTubeAnalyticsService.Scope.YtAnalyticsMonetaryReadonly, "https://www.googleapis.com/auth/youtube.readonly", "https://www.googleapis.com/auth/yt-analytics-monetary.readonly" };
I have seen youtube analytics v1 API will get deprecated on october 31st 2018. But till migration to v2 I need to fix the issue.
The issue you are probably having is that you are checking to soon Google apis exporer You will need to set the start day to two at least two days ago.
It normally takes 24 - 48 hours for data to be processed you cant see this information for today for example.
For my own channel i am seeing
"rows": [
[
"2018-09-18",
1
],
[
"2018-09-19",
2
]
To day is 2018-09-21 the most recent date i can get is the 19th which is two days ago.
I making a scheduling application and I am using iCalendar format. I am aware that I can use this code to get the free time slots from current calendar:
DateTime start = new DateTime();
DateTime end = new DateTime(start.getTime() + 1000 * 60 * 60 * 24 * 7);
VFreeBusy request = new VFreeBusy(start, end, new Dur(0, 2, 0, 0));
VFreeBusy response = new VFreeBusy(request, myCalendar.getComponents());
And I get the following output from using this code on a couple of events in the calendar.
DTSTAMP:20140323T204423Z
DTSTART:20020202T040023Z
DTEND:20020203T040023Z
DURATION:PT45M
FREEBUSY;FBTYPE=FREE:20020202T040023Z/PT2H,20020202T070023Z/PT4H,20020202T120023Z/PT16H
END:VFREEBUSY
What I don't know is how to use that VFreeBusy object with those free time slots and actually get them out, so I can compare them and use them as dates and times.
I used response.getProperties().getProperty(Property.FREEBUSY) to get the part that I need, but I don't know how to parse all that String. If you have any other ways for me to get those time slots please advise.
Assuming that you are using ical4j. Once you get the property, you can cast it to a FreeBusy property which has a getPeriods() method.