Basecamp API Calendar Event Dates - calendar

I am trying to create a calendar event for a project but the dates for the calendar event are not being properly set.
Here is the JSON data I am passing to the service
{
"summary":"New Calendar Item #2",
"description":"Details to follow",
"all_day":"false",
"starts_at":"2015-05-07T00:00:00.0000000",
"ends_at":"2015-05-12T00:00:00.0000000",
"remind_at":"2015-05-06T00:00:00.0000000",
"subscribers":"all",
"private":"false"
}
After I POST that information to the "new" Basecamp API the dates are not correct. Here are the dates that I receive back for the newly created Calendar Event:
"starts_at":"2015-05-06T20:00:00.000-04:00",
"ends_at":"2015-05-06T20:00:00.000-04:00",
"remind_at":"2015-05-05T20:00:00.000-04:00"
Not sure why the date values are off. I am assuming the dates are in proper format since I am not getting a 400 status code back.
Any help would be appreciated.
Here is a link to their documentation:
https://github.com/basecamp/bcx-api/blob/master/sections/calendar_events.md
Thanks!

If you change the format of the starts_at, ends_at and reminds_at to the following, you should get the times you expect:
"starts_at":"2015-05-07T00:00:00-00:00",
"ends_at":"2015-05-12T00:00:00-00:00",
"remind_at":"2015-05-06T00:00:00-00:00",
You could pass the timezone of the user instead if the event is to start at midnight local time:
"starts_at":"2015-05-07T00:00:00-04:00",
"ends_at":"2015-05-12T00:00:00-04:00",
"remind_at":"2015-05-06T00:00:00-04:00",

Related

Laravel timestamp columns saving with wrong date format

I recently updated an old laravel 5.7 project to 8.0 and the created_at and updated_at model timestamps get created with the wrong format. Back in the day i used this code in all models that are from a SQL Server database to get it working between my local and production environment.
public function getDateFormat()
{
if (PHP_OS_FAMILY == 'Windows') {
return 'Y-d-m H:i:s.v';
} else {
return 'Y-m-d H:i:s';
}
}
I use windows to develop the application and a Linux server to run it with apache, but after updating the project the timestamps invert the day and month of the date. For example, if i create a model in the date '2022-06-07 13:00:00' the created_at timestamp will be '2022-07-06 13:00:00'.
Of course, changing the getDateFormat() method to only return 'Y-d-m H:i:s.v' in all environments works, but create another problem with php date function, for example, if i call <p> updated at: {{ date('d/m/Y H:i:s', strtotime($model->updated_at)) }}</p> the desired result would be updated at: 07/06/2022 13:00:00 but instead i get updated at: 06/07/2022 13:00:00.
I really dont know if this is a php timezone issue or something related to laravel, since the problem shows at saving/updating rows or displaying formatted data information.
try
date("Y-d-m H:i:s", time());
Please use:
updated at: {{ date('m/d/Y H:i:s', strtotime($model->updated_at)) }}
for the desired result as the above m shows month, d shows days similarly y shows year.
Laravel have Carbon so use it for datetime stuff
use Carbon\Carbon;
...
if(! function_exists('format_date') {
function format_date(string $date): string
{
return Carbon::parse($date)->format('d-m-Y H:i:s');
// something like 31-12-2022 12:00:00, just change format as you need
}
}
From your view:
{{ format_date($model->date) }}
Make sure to check Ref

Laravel AJAX call returns a date of 1 day before

On my Laravel app, I have created an AJAX call to search bookings based on a given name. In the database, every booking contains a date field. For some reason, the date I receive from my controller query is always the day before. So for example, when the date field in the database shows '2021-05-18', the collected date from the query shows '2021-05-17'.
Does anyone have an idea what can be the cause of this and how I can solve it?
I use the same date field in other controller functions and on other views as well, and there the date field is displaying correctly.
Also, in my config > app file I have set the 'timezone' to 'Europe/Brussels'.
A screenshot of my database:
The code in my controller is as follows:
public function searchReservation(Request $request)
{
$users = User::where('name', 'LIKE', '%'.$request->name.'%')
->select('id', 'name')
->get();
foreach($users as $user) {
$user['reservations'] = Booking::where('user_id', $user['id'])->get();
}
return $users;
}
My code in the controller, where I 'transform' the date, before I create a new booking:
if (Carbon::hasFormat($request->date, 'd-m-Y')) {
$request->date = Carbon::createFromFormat("d-m-Y", $request->date);
} else {
$request->date = Carbon::createFromFormat("d-n-Y", $request->date);
}
A screenshot of my database output, where the date is always a day before the real date:
When you are using Carbon for formatting a time, you need to explicitly set the time zone if you intend to process with a time zone other than UTC. Default values like created_at will be automatically saved properly by Laravel respecting the timezone set in config/app.php. For other date/time column you need to explicitly set the timezone for formatting with Carbon. Therefore, your code should be like:
if (Carbon::hasFormat($request->date, 'd-m-Y'))
{ $request->date = Carbon::createFromFormat("d-m-Y", $request->date, config('app.timezone')); //pass timezone value from config as the third parameter
}
else {
$request->date = Carbon::createFromFormat("d-n-Y", $request->date,config('app.timezone'));
}

gatsbyjs - How to get Contentful posts filtered by year?

I'm using gatsby-source-contentful where I have a type called ContentfulBlogPost, whose schema looks something like this:
{
id
title
body
date
}
Date is a string (in YYYY-MM-DD format), auto-magically handled by Gatsby's data layer as a Moment object; I can call fromNow and formatString on it and all that.
What I want is to use GraphQL to query for a list of posts from a given year, based on that date field.
If I do this:
{
allContentfulBlogPost(
filter: { date: { regex: "/^2017/" } }
) {
...
}
}
then I get this error: "Cannot read property 'fromNow' of undefined"
What I really want is to be able to filter the allContentfulBlogPost data set by date, either by transforming the date into an integer/string year and finding on that, or by asking for all items whose date falls between Jan 1 and Dec 31 of the given year.
Right now, I have a query running in gatsby-node that pulls in all blog posts, then groups them by year in JS and then passes the array of posts into a template. This works, but it really seems like there should be a GraphQL way of doing this?

Calendar 2 ionic

I have a calendar on my ionic app and there is an API that brings me events from database.
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://portalemme2.com.br/SaoJoseAPI/agenda', true);
this.http.get('http://portalemme2.com.br/SaoJoseAPI/agenda').map(res => res.json()).subscribe(vetor => {
this.eventos = vetor.eventos;
});
How can I change the date format to appear on calendar?
Every event has an date like '2018-01-01' and an hour like '01:00:00.0000000' (from database)
But the calendar from ionic only accepts date in this format '2017-12-16 01:00:00'
I need to transform all dates to push in "this.eventos" array.
You can use moment.js, an excellent and easy to use library to manipulate dates. You should use data returned from the server to construct a Moment object pasing them to the moment() function and then, use format method to convert date to the format required by Calendar. In your case, to convert to these format, you should pass to format method something like "YYYY-MM-DD HH:MM:SS".

Posting date values in REST service will not create date fields in the Domino back end

I'm creating an AngularJS HTML app using Domino in the back-end. The communication is 100% rest-based via DDS
When I send date values they don't get converted to date items on the Domino document. The values are always stored as strings
I have tried various formats on the date string with no luck
Does anyone know is this is even possible with the Domino Data Services ?
I'm using Angulars $http service with the PATCH method to update changed values only
It is possible to store/ update a data in a document using Domino Data Services.
To get it to work you need to send the date as a string in ISO 8601 Extended format. That's the format that the toISOString() function returns in JavaScript for a Date object. On the form that you're trying to create or update, you'll need to have that field added as a Date/Time field. Adding the computewithform parameter to the request isn't required.
Here's a sample JSON object that, when send as a POST or PATCH request to DDS, will create/ update the LastVisit field as a DateTime field (assuming that field is on the form).
{
"FirstName":"Barney",
"LastName":"Bloomberg",
"LastVisit" : "2013-12-21T12:18:18Z"
}
The field name in the json string must be EXACTLY as on the form.
I had the similar problem where I had a field called 'TTL' on the form but my json generated by API using a class the field was named 'ttl'.
This resulted in a String as value for the date field, not a date.
This works :-)
I have extended the sample that I used in my presentation in the following way:
Added a field "WakeupTime" on the form. Set it to Date/Time, and select to display date and time. The sample output is 08-01-2016 16:11:42.
So reading the sample data using this url:
.../json.nsf/api/data/documents/unid/33735D0BCE799E01C1257CC3007A7221
I get something like this back:
{
"#href": "/demo/json.nsf/api/data/documents/unid/33735D0BCE799E01C1257CC3007A7221",
"#unid": "33735D0BCE799E01C1257CC3007A7221",
"#noteid": "902",
"#created": "2014-04-23T22:17:26Z",
"#modified": "2016-01-08T15:09:57Z",
"#authors": [
"Anonymous",
"CN=John Dalsgaard/O=D-D"
],
"#form": "Person",
"Unid": "33735D0BCE799E01C1257CC3007A7221",
"Key": "33735D0BCE799E01C1257CC3007A7221",
"Name": "Peter Hansen",
"Email": "ph#mail.dk",
"YearBorn": 1955,
"WakeupTime": "2016-08-01T05:33:10Z"
}
Important! - this gives me the exact format that I need to use for the WakeupTime field!
So if I then post a PATCH back with select fields:
{
"Email":"peter.hansen#mail.dk",
"YearBorn":1953,
"WakeupTime":"2016-01-08T05:33:40Z"
}
... and re-read the data then the fields are updated. And if I check in the Notes client I can see that the field is a date/time field :-)
Same happens if I create a new entry/document - the field is still the right type.
You have to be very aware of how you handle timezones though! The data are transferred as GMT :-)

Resources