Google calendar API issue - daylight saving - asp.net-web-api

I made an application using the Google calendar API, to evaluate events and finally also adds an event to a calendar. Now we come close to the switch to daylight saving time I have the problem: the API is shifting time for one hour.
Example:
$event = new Google_Service_Calendar_Event(array(
'summary' => 'title',
'description' => 'description',
'start' => array(
'dateTime' => '2018-04-05T12:00:00+1:00',
'timeZone' => 'Europe/Amsterdam',
),
'end' => array(
'dateTime' => '2018-04-05T15:00:00+1:00',
'timeZone' => 'Europe/Amsterdam',
)
));
$event = $cal->events->insert($room_calendar_id, $event);
When I execute this code the result is an event that runs from 13:00 till 16:00 hrs. When I use these parameters via the Google calendar API try-out function it gives the same result. But in the latter case it comes back with following JSON response:
"start": {
"dateTime": "2018-04-20T13:00:00+02:00",
"timeZone": "Europe/Amsterdam"
},
"end": {
"dateTime": "2018-04-20T16:00:00+02:00",
"timeZone": "Europe/Amsterdam"
}
So weird it shows an offset of +02:00.
I would expect the API does not change the time and offset parameters.
When I do the same for 2018-03-20 it works fine, so daylight saving should cause this issue in my opinion.
Can someone give more information on how I should add an event without considering the daylight saving influence?

Timezones - such as Europe/Amsterdam - have Daylight Saving effects, and you can't help avoiding them, because DST is part of the things controled by timezone definitions.
And during DST, the offset used in Amsterdam is changed from +01:00 to +02:00. So this is not weird, it's actually the expected behaviour.
What google API is doing - probably - is adjusting an invalid offset (2018-04-05T12:00:00+01:00) to a valid one (2018-04-05T13:00:00+02:00) - btw, both correspond to the same UTC instant, so the conversion is fine.
This doesn't happen in March 20th because DST haven't started yet - in 2018, it starts on March 25th.
If you're dealing with timezones, there's no way to ignore DST effects, because DST is part of the timezone definition.

Related

Laravel localization file format error: array() versus [] format

I am struggling a bit with localization in Laravel 5.3 (with php 7). The default localizaiton file format in Laravel 5.3 is using brackets, as in this example:
return [
'footer.contact.email' => 'Email:',
]
That's what I have been using in my app and it's working fine. But now I am trying to work with some packages to help with translations, for example:
https://github.com/potsky/laravel-localization-helpers
https://github.com/barryvdh/laravel-translation-manager
But both of those generate localization files in the "old" laravel 4.x array format. For example
return array(
'footer' => array(
'contact' => array(
'email' => 'Email:',
),
),
);
As I understand it I should have no issue with this localization file format in my laravel 5.3 app, however it's always throwing an exception:
[2016-12-02 13:26:01] local.ERROR: ErrorException: htmlspecialchars() expects parameter 1 to be string, array given in C:\100_source_code\consulting_platform_laravel\maingig\vendor\laravel\framework\src\Illuminate\Support\helpers.php:519
Stack trace:
#0 C:\100_source_code\consulting_platform_laravel\maingig\vendor\sentry\sentry\lib\Raven\Breadcrumbs\ErrorHandler.php(36): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'htmlspecialchar...', 'C:\\100_source_c...', 519, Array)
I really cant understand why this format is not working with my app. I bet it is something trivial that I am missing, but any help would be very welcome!
Thanks,
Christian
After a few extra hours of stepping through the code I found the source of the problem.
For example, I got these in my original lang file:
'footer.subscribe' => 'SUBSCRIBE TO OUR NEWSLETTER',
'footer.subscribe.intro' => 'Be the first to know about our latest news...',
'footer.subscribe.privacy' => 'Privacy Policy',
'footer.subscribe.tos' => 'Terms of Service',
'footer.subscribe.tac' => 'Terms and Conditions',
As I tried to use both of the packages mentioned in my original question they produced the following output:
'footer' =>
array (
'subscribe' =>
array (
'intro' => 'TODO: intro',
'privacy' => 'TODO: privacy',
'tos' => 'TODO: tos',
'tac' => 'TODO: tac',
),
),
As you can see the generated file dropped the value for the text footer.subscribe and only kept the child element, intro, privacy, tos and tas in this case. Therefore a request for trans('footer.subscribe') returns an array and not the text.
Now that I know this I will change the format of my original translation file!
c.

Unable to programmatically create tags in GitHub - ISO8601 timestamp is invalid

In my lumen app I'm trying to programmatically create tags a GitHub repo. My setup is working great except something is up with the tagger.date that I can't figure out. The API is telling me that the timestamp is not valid:
[Github\Exception\RuntimeException]
Invalid request.
2016-07-10T13:32:07+0000 is not a valid date-time.
However the timestamp included in the error message appears to be correctly formatted based on the documentation.
$github->git()->tags()->create(
$githubConfig['namespace'],
$githubConfig['repository'],
[
'tag' => $this->version->patchTag(),
'tagger' => [
'name' => config('github.tagger.name'),
'email' => config('github.tagger.email'),
'date' => Carbon::now()->toIso8601String()
],
'message' => 'This release was automatically published by [Game-Watcher](https://github.com/bkuhl/game-watcher).',
'object' => $masterBranch['commit']['sha'],
'type' => 'commit'
]
);
This fiddle indicates the time format is valid.
Try using Carbon::now()->toAtomString() instead.
Carbon's common formatting methods are "wrappers for the common formats provided in the DateTime class".
The documentation for DateTime::ISO8601 carries this warning:
Note: This format is not compatible with ISO-8601, but is left this way for backward compatibility reasons. Use DateTime::ATOM or DATE_ATOM for compatibility with ISO-8601 instead.
The relevant difference appears to be with the timezone offset. DateTime::ISO8601 uses +0000 for UTC, while DateTime::ATOM uses +00:00.

Using Ruby & Github API to filter commits by date

I am using the ruby gem 'octokit' which implements the Github API v3. Mostly works great but I cannot seem to filter by date. I believe I have the syntax and time format correct, but it appears my option is ignored and the API returns the past 35 entries regardless of the since or until dates.
Here's a minimal reproducible example (after installing the octokit gem).
require 'octokit'
require 'time'
#day = "2012-09-27"
#until = DateTime.parse(#date).iso8601
#since = (DateTime.parse(#day) - 60*60*48).iso8601
a = Octokit.commits({:username => "cboettig", :repo => "labnotebook", :since => #since, :until => #until})
see the date of the output of last entry
a.last.commit.author.date
explicit day doesn't work either
b = Octokit.commits({:username => "cboettig", :repo => "labnotebook", :since => "2012-09-27T00:00:00+00:00"})
b.last.commit.author.date
The date I get in both examples is from August, outside the specified range given. What did I miss?
Background: I'm trying to write a little Jekyll plugin that uses the API to return commits made to a specified repo on the day of the post.
joeyw gives a great answer to this question here.
The second argument should be the sha or branch, and options should be the third argument, e.g.
Octokit.commits("cboettig/labnotebook", "master", :since => "2012-09-28T00:00:00+00:00").length
or
Octokit.commits("cboettig/labnotebook", nil, :since => "2012-09-28T00:00:00+00:00").length
works just fine. Here's my corresponding jekyll plugin

InstantCommons not working in MediaWiki 1.19 and SELinux

I am setting my own MediaWiki website locally, and am not able to get the InstantCommons feature to work (used to directly embed files from commons.wikimedia.org).
I get no error message, the files I try to load from Commons using the following syntax:
[[File:Cervus elaphus Luc Viatour 1.jpg|Cervus elaphus Luc Viatour 1]]
are just not loaded, and I end up with a red link on my page, referring to a non-existing file. It has been 2 days now that I am looking for a solution, but so far without any success.
I am running:
MediaWiki v.1.19.1
Fedora 16 (with SElinux)
PHP 5.3.15
MySQL Ver 14.14 Distrib 5.5.25a, for Linux (x86_64)
I have tried the following two configurations in my LocalSettings.php, without success:
$wgUseInstantCommons = true;
AND
$wgForeignFileRepos[] = array(
'class' => 'ForeignAPIRepo',
'name' => 'shared',
'apibase' => 'http://commons.wikimedia.org/w/api.php',
'fetchDescription' => true, // Optional
'descriptionCacheExpiry' => 43200, // 12 hours, optional (values are seconds)
'apiThumbCacheExpiry' => 43200, // 12 hours, optional, but required for local thumb caching
);
Any suggestion is most welcome.
OK, this is not (yet) an answer, but a debugging suggestion. It looks to me like the HTTP request from your server to Commons is failing for some reason, but unfortunately ForeignAPIRepo doesn't indicate the cause of the error in any way.
This is really a bug in MediaWiki, and should be fixed, but in the mean time, could you please try applying the following diff (or just manually adding the line marked with the + sign) to your includes/filerepo/ForeignAPIRepo.php file:
Index: includes/filerepo/ForeignAPIRepo.php
===================================================================
--- includes/filerepo/ForeignAPIRepo.php (revision 97048)
+++ includes/filerepo/ForeignAPIRepo.php (working copy)
## -385,6 +385,7 ##
if ( $status->isOK() ) {
return $req->getContent();
} else {
+ wfDebug( "ForeignAPIRepo: HTTP GET failed: " . $status->getXML() );
return false;
}
}
After applying it, try loading the file description page for a Commons image and look at the MediaWiki debug log. There should now be a line starting with ForeignAPIRepo: HTTP GET failed: followed by a few lines of XML error dump. That error data should hopefully indicate what's going wrong; please copy and paste it here.
Mine is not a definitive answer either. Referring to Ilmari Karonen's post, I was unable to find or get the getXML() method to execute for my version of Mediawiki v1.23.0. I was looking at the reference documentation found here to try and find any other method calls on the Status class that would give me good troubleshooting info. I ended up finding the following and editing the same file as mentioned in Ilmari Karonen's post includes/filerepo/ForeignAPIRepo.php beginning at line #521:
if ( $status->isOK() ) {
return $req->getContent();
} else {
$error = $status->getErrorsArray();
$dump = print_r($error, true);
wfDebug("ForeignAPIRepo: HTTP GET failed: $dump\n");
return false;
}
The default InstantCommons configuration of older MediaWikis is a bit silly. Due to T114098 I recommend one of the following, which will hopefully fix your problems:
upgrade to MediaWiki 1.27 (when it's released), or
set your LocalSettings.php to hotlink images to save on server-side requests and processing.
$wgUseInstantCommons = false;
$wgForeignFileRepos[] = array(
'class' => 'ForeignAPIRepo',
'name' => 'commonshotlink',
'apibase' => 'https://commons.wikimedia.org/w/api.php',
'hashLevels' => 2,
'url' => 'https://upload.wikimedia.org/wikipedia/commons',
'thumbUrl' => 'https://upload.wikimedia.org/wikipedia/commons/thumb',
'transformVia404' => true,
'fetchDescription' => true,
'descriptionCacheExpiry' => 43200,
'apiThumbCacheExpiry' => 24 * 3600,
);

How to access Youtube_it ruby query results?

I am trying to implement the youtube_it youtube api wrapper for ruby and have it working except I'm stumped as to how the query results should be accessed.
Here is my query:
client.videos_by(:query => "penguin", :max_results => 1)
Submitting request [url=http://gdata.youtube.com/feeds/api/videos?max-results=1&start-index=1&vq=penguin].
=> #<YouTubeIt::Response::VideoSearch:0xb6c41b14 #feed_id="http://gdata.youtube.com/feeds/api/videos", #updated_at=Wed Nov 03 18:01:39 UTC 2010, #videos=[#<YouTubeIt::Model::Video:0xb6c424d8 #thumbnails=[#<YouTubeIt::Model::Thumbnail:0xb6c6b694 #url="http://i.ytimg.com/vi/oSbLpQEZP1Y/2.jpg", #width=120, #height=90, #time="00:01:34">, #<YouTubeIt::Model::Thumbnail:0xb6c6b248 #url="http://i.ytimg.com/vi/oSbLpQEZP1Y/1.jpg", #width=120, #height=90, #time="00:00:47">, #<YouTubeIt::Model::Thumbnail:0xb6c6a988 #url="http://i.ytimg.com/vi/oSbLpQEZP1Y/3.jpg", #width=120, #height=90, #time="00:02:21">, #<YouTubeIt::Model::Thumbnail:0xb6c69e34 #url="http://i.ytimg.com/vi/oSbLpQEZP1Y/0.jpg", #width=320, #height=240, #time="00:01:34">], #categories=[#<YouTubeIt::Model::Category:0xb6ca5d6c #term="Music", #label="Music">], #noembed=false, #racy=false, #favorite_count=7862, #duration=188, #author=#<YouTubeIt::Model::Author:0xb6c9942c #name="wili", #uri="http://gdata.youtube.com/feeds/api/users/wili">, #updated_at=Tue Nov 02 08:45:25 UTC 2010, #longitude=nil, #position=nil, #view_count=1682350, #html_content="penguin", #media_content=[#<YouTubeIt::Model::Content:0xb6c770d4 #url="http://www.youtube.com/v/oSbLpQEZP1Y?f=videos&app=youtube_gdata", #duration=188, #format=#<YouTubeIt::Model::Video::Format:0xb656d108 #name=:swf, #format_code=5>, #default=true, #mime_type="application/x-shockwave-flash">, #<YouTubeIt::Model::Content:0xb6c766d4 #url="rtsp://v5.cache3.c.youtube.com/CiILENy73wIaGQlWPxkBpcsmoRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp", #duration=188, #format=#<YouTubeIt::Model::Video::Format:0xb656d11c #name=:rtsp, #format_code=1>, #default=false, #mime_type="video/3gpp">, #<YouTubeIt::Model::Content:0xb6c75d38 #url="rtsp://v8.cache3.c.youtube.com/CiILENy73wIaGQlWPxkBpcsmoRMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp", #duration=188, #format=#<YouTubeIt::Model::Video::Format:0xb656d0f4 #name=:three_gpp, #format_code=6>, #default=false, #mime_type="video/3gpp">], #description="penguin", #latitude=nil, #title="penguin", #published_at=Mon May 08 18:11:01 UTC 2006, #player_url="http://www.youtube.com/watch?v=oSbLpQEZP1Y&feature=youtube_gdata_player", #rating=#<YouTubeIt::Model::Rating:0xb6c5eb4c #min=1, #max=5, #average=4.676985, #rater_count=2746>, #keywords=["pigloo", "penguin"], #video_id="http://gdata.youtube.com/feeds/api/videos/oSbLpQEZP1Y", #where=nil>], #total_result_count=291282, #offset=1, #max_result_count=1>
I would like to retrieve the URL and thumbnail links. Any ideas?
I don't have a great deal of knowledge of this particular gem, but your answer should at least be close to this. You can access the object directly through the videos accessor, which will give you the video object, on which thumbnails each have a url. so you could do the following:
reply = client.videos_by(:query => "penguin", :max_results => 1)
reply.videos.first.thumbnails.first.url # the thumbnail for the first video
reply.videos.first.player_url # The website for the video
reply.videos.first.media_content.first.url # direct embed url
It might be useful to search for some ruby beginners guides to help catch you up to speed as well. Good luck!
william's answer is correct, when you do it
client.videos_by(:query => "penguin", :max_results => 1)
this return an array called videos, so you just need iterate it
client.videos.each do |video|
video.title
video.thumbnails
video.video_id
end
good luck!

Resources