Skip to main content

Solutions In Drupal

Time Zone Handling in Drupal 7favorite
I got a below scenario in one of my project and i was totally strucked up .Dont know how to proceed further , Any help is much appreciated
I have a date field saved as Unix timestamp with site's timezone .With the new requirement, have new local timezone field with limited options so that admin enter can enter the event date with the local timezone where that event actually happen.
For Example in the date field they may enter Apr 04 2018 07:00 am and the local timezone field is maintained by creating select field with limited option as EST, CDT, MST etc..., so they can use choose any one of them.
I have created the views for the next immediate event by comparing the relative date
using the result date need to display the counter like functionality for example 1days : 30 hours: 15mins: 20 seconds.
To make a counter have using the javascript in view field tpl
var event_date = ;// View output in date format
var countdown = new Date (event_date).getTime(); //event date in timestamp
var local_time = new Date().getTime();// clent local time in timestam
var distance = countdown - local_time;
var days = Math.floor(distance / (1000 * 60 * 60 * 24)); var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000);
Now its working only for site's time zone . What am expecting is ,if a user enter the event date in CDT time zone , then site display the exact time diffence when the event going to start at their timezone(local)...

Comments

Popular posts from this blog

Redirection In Drupal 8 Programatcially

Redirection In Drupal 8  In this post we can learn about the ways we can make redirect in Drupal 8. You can make a custom redirect according to the context in many ways. Form Redirect      We can use the formstate object to redirect from form.     Currently below two methods are available from Drupal\Core\Form  formstate to build  a    \Symfony\Component\HttpFoundation\RedirectResponse  for redirection. 1) setRedirect  function setRedirect($route_name, array $route_parameters = [], array $options = []) This method will call the setRedirectUrl function inside it. 1) route_parameters - optional argument 2) route_name -  The name of the route name. 3) options -    (optional) An associative array of additional URL options, with the    *   following elements:    *   - 'query': An array of query key/value-pairs (without any URL-encoding)    *...

Twig in Drupal 8

                                             Twig in Drupal 8 Introduction   In web development , every developer knows  presenting  a content in a  webpage is more important than any  functional logic inside the website whether the site is for tutoring , just a blog or its site for ecommerce products , how your site going to interact with the user plays major role for your business profit . Its a matter of minute to hold your customer/user in online to make a profit. you may thought , it is inappropriate to discuss those  with the title of this post  twig in drupal 8.   twig is used as presenter of your content in an easy way. Templating Engine in drupal 7     For those who are familiar with drupal 7 already know that php is used as templating engine . So its with an advantage of adding much m...

Process of page request to response in Drupal 8 - Part 1

For every drupal developer is it necessary to know the under the hood process of how drupal internally works and some of them may already know  page rendering process of drupal 7. Lets see the Process of User Request to Response in  two parts: PART 1: Step 1:  The user make a request in the browser in the form of url for example: www.example.com Step 2:  The browser will pass the request to the Web server where the website  resides(Here Drupal makes website...) Step 3: In drupal , every request is handled via index.php file ,while digging into index file we may see the following lines as shown in the image. Note:  Symfony is a playing a major role  in  drupal 8 and drupal 8 follows the object oriented style of programming .. Components used from symfony in drupal 8.  So as you see , there is a two use statements  1.use Drupal\Core\DrupalKernel 2.use Symfony\Component\Ht...