how to format date time for ical and outlook calendar - outlook

I am trying to add events to google,outlook and ical calendar. Adding event to google calendar is working just fine but for outlook and ical there is some issue in time.
When i add start time as 1:00 pm and end time as 12:00 am for the same date ical is generating end time as 12:00 am and end time as 1:00 pm. I am generating ical as follows. I don't know what am i doing wrong ? Any help/suggestions is appreciated.
$startDate = $_GET['startDate'];
$startTime = $_GET['startTime'];
$startDateTime = $startDate . ' ' . $startTime; //2020-10-08 13:00:00
$endDate = $_GET['endDate'];
$endTime = $_GET['endTime'];
$endDateTime = $endDate . ' ' . $endTime; //2020-10-08 00:00:00
$subject = $_GET['subject'];
$desc = $_GET['desc'];
$location = $_GET['location'];
$filename = $subject . '.ics';
$format = 'Y-m-d H:i:s';
$icalformat = 'Ymd\THis';
$startDateTime = DateTime::createFromFormat($format, $startDateTime);
$startDateTime = $startDateTime->format( $icalformat );
$endDateTime = DateTime::createFromFormat( $format, $endDateTime );
$endDateTime = $endDateTime->format( $icalformat );
$ical = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:" . md5( uniqid( mt_rand(), true ) ) . "example.com
DTSTAMP:" . gmdate('Ymd') . 'T' . gmdate( 'His' ) . "
DTSTART:" . $startDateTime . "
DTEND:" . $endDateTime . "
LOCATION:" . $location . "
SUMMARY:" . $subject . "
DESCRIPTION:" . $desc . "
END:VEVENT
END:VCALENDAR";
//set correct content-type-header
header( 'Content-type: text/calendar; charset=utf-8' );
header( 'Content-Disposition: attachment; filename=' . $filename );
echo $ical;
exit;

How can the end time be earlier than the start time? Should it not be the midnight of the next day? 2020-10-09 00:00:00.

Related

Magento 2.4.5: How to get Stripe payment information object in Observer class or otherwise

With the upgrade to Magento 2.4.5 from 2.4.2, the old code in an observer class in a custom module to get information about Stripe Payment isn't working any more. It looks like Magento event sales_order_place_after isn't able to help with retrieving payment information. I tried several other events including sales_order_load_after sales_order_save_before sales_order_save_after sales_order_delete_before sales_order_delete_after and checkout_submit_all_after.
Below is a part of the test program:
$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
// Initial code to Bootstrap Magento 2 ends here
/*************************************************************************************************/
$date = $timezone->date();
// If one needs to diplay date in the formate of Ymd use 'Ymd'
$current_store_time = $date->format('Ymd H:i:s');
echo "<body>";
echo "**********************************************Magento Store Time : " . $current_store_time . "**********************************<br><br>";
// Sanitize the $_GET[] value
// redirect if the message parameter is invalid.
if (isset($_GET["order_id"])) {
if (htmlspecialchars($_GET["order_id"]) == "invalid_id") {
echo "Please ensure to enter the valid order ID by replacing invalid_id` with valid order ID in the URL";
exit;
}
}
// Sanitize the $_GET[] value
// Create an object of the order loaded with the $order_id passed as query string.
$orderId = htmlspecialchars($_GET["order_id"]);
$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementID($orderId);
if ($order->getEntityId()) {
echo "*********************************************Get Order Information: " . '*************************************************<br>';
echo "Entity ID: " . $order->getEntityId() . '<br>';
echo "Increment ID: " . $order->getIncrementId() . '<br>';
echo "State: " . $order->getState() . '<br>';
echo "Status: " . $order->getStatus() . '<br>';
echo "Store ID: " . $order->getStoreId() . '<br>';
echo "Grand Total: " . $order->getGrandTotal() . '<br>';
echo "SubTotal: " . $order->getSubtotal() . '<br>';
echo "Total Quantity" . $order->getTotalQtyOrdered() . '<br>';
echo "Currency Code: " . $order->getOrderCurrencyCode() . '<br><br>';
echo "Discout Applied: " . $order->getDiscountAmount() . '<br><br>';
// Get Customer Information from the Order
echo "Get Customer Information: " . "<br>";
echo "Customer Email : " . $order->getCustomerEmail() . '<br><br>';
echo "<br><b>**********************Testing with getAllVisibleItems() function call************</b><br>";
//error_log(print_r($order->getAllVisibleItems()));
$orderItems = $order->getAllVisibleItems();
foreach ($orderItems as $orderItem) {
echo ("SKU = " . $orderItem->getSku() . "<br>");
echo ("Name = " . $orderItem->getName() . "<br>");
echo ("Price = " . $orderItem->getPrice() . "<br>");
echo ("Qty = " . $orderItem->getQtyOrdered() . "<br>");
}
echo "<br>";
// Get Order Payment Information
echo "Get Payment Information: " . "<br>";
$payment = $order->getPayment();
$stripePayment = $objectManager->get('\Magento\Sales\Model\Order\Payment');
$this->logger->debug("CC Last 4 digits " . $stripePayment->getCcLast4());

How to calculate difference between two dates as day month year using carbon in laravel

I want to calculate difference between two dates as day,month and year.
What I did :
$year = Carbon::now()->diffInYears($row->entry_date);
$month = Carbon::now()->diffInMonths($row->entry_date);
$day = Carbon::now()->diffInDays($row->entry_date);
$month = $month > 12 ? $month-(12*$year) : $month;
$day = $day>30 ? $day-((365*$year)+($month*30)) : $day;
return '<td>' . $year . ' Year ' . $month . ' Month ' . $day . ' Day ' . '</td>';
when i do it this way i am calculating wrong. Is there a method in Carbon to calculate this correctly?
I found a short and simple way
$time = Carbon::now()->diff($row->entry_date);
return '<td>' . $time->y . ' Year' . $time->m . ' Month' . $time->d . ' Day' . '</td>';
You may use some logic like this:
$entry_date = Carbon::parse("1992-05-18 00:00:00");
$year = Carbon::now()->diffInYears($entry_date);
$entry_date->addYears($year);
$month = Carbon::now()->diffInMonths($entry_date);
$entry_date->addMonths($month);
$day = Carbon::now()->diffInDays($entry_date);
return '<td>' . $year . ' Year ' . $month . ' Month ' . $day . ' Day ' . '</td>';
you can use this but adjust according to your own code
public function validationDays_remaining($date){
$valid_date = Carbon::parse($date)->toDateString();
$valid_date = date('Y.m.d\\TH:i', strtotime($valid_date));
$today = new \DateTime();
$today->setTime(0, 0, 0);
$match_date = \DateTime::createFromFormat("Y.m.d\\TH:i", $valid_date);
$match_date->setTime(0, 0, 0);
$diff = $today->diff($match_date);
$diffDays = (integer)$diff->format("%R%a");
return $diffDays;
}
$seconds = Carbon::now()->diffSeconds($row->entry_date);
CarbonInterval::seconds($seconds)->cascade()->forHumans();

Send Meeting invite to outlook room using php

The idea is to send a email via PHP mailer to office365 Room email ID with meeting start time and end time, now once the meeting request is accepted by the Microsoft exchange, I need to see that in room calendar in my outlook.
I already tried an approach with Icalendar, here is the ics format which i'm sending through php.
'PRODID:-//Microsoft Corporation//Outlook 10.0 MIMEDIR//EN' . "\r\n" .
'VERSION:2.0' . "\r\n" .
'METHOD:REQUEST' . "\r\n" .
'BEGIN:VTIMEZONE' . "\r\n" .
'TZID:Eastern Time' . "\r\n" .
'BEGIN:STANDARD' . "\r\n" .
'DTSTART:20091101T020000' . "\r\n" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11' . "\r\n" .
'TZOFFSETFROM:-0400' . "\r\n" .
'TZOFFSETTO:-0500' . "\r\n" .
'TZNAME:EST' . "\r\n" .
'DTSTART:20090301T020000' . "\r\n" .
'RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3' . "\r\n" .
'TZOFFSETFROM:-0500' . "\r\n" .
'TZOFFSETTO:-0400' . "\r\n" .
'TZNAME:EDST' . "\r\n" .
'BEGIN:VEVENT' . "\r\n" .
'ORGANIZER;CN="'.$from_name.'":MAILTO:'.$from_address. "\r\n" .
'ATTENDEE;CN="'.$to_name.'";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:'.$to_address. "\r\n" .
'LAST-MODIFIED:' . date("Ymd\TGis") . "\r\n" .
'UID:'.date("Ymd\TGis", strtotime($startTime)).rand()."#".$domain."\r\n" .
'DTSTAMP:'.date("Ymd\TGis"). "\r\n" .
'DTSTART;TZID="Pacific Daylight":'.date("Ymd\THis", strtotime($startTime)). "\r\n" .
'DTEND;TZID="Pacific Daylight":'.date("Ymd\THis", strtotime($endTime)). "\r\n" .
'TRANSP:OPAQUE'. "\r\n" .
'SEQUENCE:1'. "\r\n" .
'SUMMARY:' . $subject . "\r\n" .
'LOCATION:' . $location . "\r\n" .
'CLASS:PUBLIC'. "\r\n" .
'PRIORITY:5'. "\r\n" .
'BEGIN:VALARM' . "\r\n" .
'TRIGGER:-PT15M' . "\r\n" .
'ACTION:DISPLAY' . "\r\n" .
'DESCRIPTION:Reminder' . "\r\n" .
'END:VALARM' . "\r\n" .
'END:VEVENT'. "\r\n" .
'END:VCALENDAR'. "\r\n";
But here the issues is, this is working only with my outlook email ID that means when send the mail it will show on the calendar. if tried to give room (which i created in office 365 admin panel) email ID it is not showing up.
Also I recently cam across with the term called
Exchange Web Services (EWS)
but I don't have a clue how to start with and integrate in PHP.
Please let me know any suggestion or pointers.
Thanks in advance.
I have found the answer for this. basically I need to enable set-caledarProccess settings at exchange online.

Backup2mail can't send email with database backup..multiple or malformed newlines?

Until 18 June I received all days my backup database on Gmail without problems, I had finally found the solution for this. But after 18 June emails with database are stopped. I don't receive neither normal email with only log file txt..nothing I receive now.
I use Backup2mail http://www.backup2mail.com/
PHP Version 5.6.13, Ubuntu Linux 14.04.1
The database backup file is perfectly created on server but it can't send more to Gmail.
I have this error in index.php file of Backup2mail:
Warning: mail(): Multiple or malformed newlines found in additional_header in > /srv/users/serverpilot/apps/myappname/public/backuptomail/index.php on line 119
Database not sent! Please check your mail settings.
Sent? No
On line 119 there is:
if (mail($send_to, $subject, $body, $headers)) {
$sent = 'Yes';
echo ($file_is_db ? 'Backup file' : 'Report') . ' sent to ' . $send_to . '.<br />';
if ($file_is_db) {
if ($delete_backup) {
unlink($file);
echo 'Backup file REMOVED from disk.<br />';
} else {
echo 'Backup file LEFT on disk.<br />';
}
}
} else {
echo '<span style="color: #f00;">' . ($file_is_db ? 'Database' : 'Report') . ' not sent! Please check your mail settings.</span><br />';
}
echo 'Sent? ' . $sent;
Where is the problem? :( Maybe from 18 june PHP is upgraded and changed something? I'm not expert.
Thank you in advance
The problem is a recent update in PHP. Under this update you can no longer have multiple (\n) new lines in the header. Thus you need to remove the newlines in a few places.
Find the following lines and remove the trailing \n (leave just one):
$body = 'Database backup file:' . "\n" . ' - ' . $file . "\n\n";
$headers .= 'Content-Transfer-Encoding: base64' . "\n\n";
However you also need to remove the \n in the following line as well:
$headers .= chunk_split(base64_encode(implode('', file($file)))) . "\n";
change it to:
$headers .= chunk_split(base64_encode(implode('', file($file)))) . "";
It should work after these changes.
Hope this helps you out mate.

How to reduce minutes but add hours in php

How can I add hours as well as subtract minutes to get one result?
I can add 4 hours using the following code:
//Current Time
$hourMin = date('H:i:s');
echo "Current time is: ". $hourMin."<br>";
$hourDiff = date('H:i:s', time()+14400000);
echo "New time is: " . $hourDiff;
I can subtract 7 minutes using the following code:
//Current Time
$hourMin = date('H:i:s');
echo "Current time is: ". $hourMin."<br>";
$hourDiff = date('H:i:s', time()-420000);
echo "New time is: " . $hourDiff;
How do I do this so that my time in variable $hourDiff is 4 hours ahead but 7 minutes behind?
$now = date("H:i:s", time());
$newTime = strtotime("$now +4 hours -7 minutes");
or
$newTime = strtotime("$now +3 hours +53 minutes");
echo "New time is: " . date("H:i:s", $newTime);
something like this?

Resources