hey guys i'm new in ubercart and drupal, im trying to create a custom-able uc_lto like jstimer i like to omit the hours, min and sec, put the leading zero and create consistent format in hh:mm:ss, without having one of the field disappear when the value is 0.

Any suggestion, would be appreciated

cheers,

Bondan

Comments

joshicsin’s picture

I would like to display only cumulative time like hours, minutes and seconds and not the days or anything else.
I have tried to modify the module but it didn't help either.

Can you show us a way using which we can modify the display of the timer in the way we want?

I really appreciate your efforts.

Regards.

siddhen’s picture

I'm working on the same thing right now.
Here is how to change the appearance of the timer to HH MM SS.
In the us_lto setting page set the 'Time interval granularity' to 3 and follow the instruction in the Active Timer Javascript Settings.
You need to copy the uc_lto.js to your theme folder and change Drupal.formatInterval function as follow (delete the old one and past this one).

Drupal.formatInterval = function(timestamp, granularity, langcode) {
  granularity = parseInt(granularity, 10) || 2;
  langcode = langcode || null;
  var units = [
   
    {
      'singular' : '01 ',
      'plural' : '@count :',
      'secs' : 3600
    },
    {
      'singular' : '01 ',
      'plural' : '@count :',
      'secs' : 60
    },
    {
      'singular' : '01 ',
      'plural' : '@count ',
      'secs' : 1
    }
  ],
    output = '';
  $.each(units, function(i, val) {
    if (timestamp >= val.secs && granularity > 0) {
	   if(Math.floor(timestamp / val.secs)<10){	      	 
	      val.plural = '0@count ';
	   }
          output += (output ? ' ' : '') + Drupal.formatPlural(Math.floor(timestamp / val.secs), val.singular, val.plural, {}, langcode);
      timestamp %= val.secs;
      granularity--;
    }
    if (granularity === 0) {
      return false;
    }
  });
  return output ? output : Drupal.t('0 sec', {}, langcode);
};

It still need work for displaying 00 when timer reach zero in the sec minutes or hours section.
any help will be appreciated.

joshicsin’s picture

Great!
Thanks a million.

This worked.

Regards.

joshicsin’s picture

The code is working fine except when you have hours <10 and it shows like thos 09 25 : 30. Also, it would be nice if any how we can display the coutndowd as 00 : 05 : 50.
I tried but not able to get it done.
I'd highly appreciate your suggestion.

Regards.

siddhen’s picture

Here is a code to display the coutndowd as 00 : 05 : 50

Drupal.formatInterval = function(timestamp, granularity, langcode) {
  granularity = parseInt(granularity, 10) || 2;
  langcode = langcode || null;
  var units = [
   
    {
      'singular' : '01 :',
      'plural' : '@count :',
      'secs' : 3600
    },
    {
      'singular' : '01 :',
      'plural' : '@count :',
      'secs' : 60
    },
    {
      'singular' : '01 ',
      'plural' : '@count ',
      'secs' : 1
    }
  ],
    output = '';
  $.each(units, function(i, val) {
 
    if (granularity > 0) {
	
	   if(Math.floor(timestamp / val.secs)<10){	      	 
        if 	(val.secs ==1){    
		  val.plural = '0@count ';
		}
		else{
		  val.plural = '0@count :';
		}
	   }
	   if(Math.floor(timestamp / val.secs)==0){	      	 
		   if 	(val.secs ==1){   
		  val.plural = '00 ';
		}
		else{
		  val.plural = '00 :';
		}
	   }
          output += (output ? ' ' : '') + Drupal.formatPlural(Math.floor(timestamp / val.secs), val.singular, val.plural, {}, langcode);
      timestamp %= val.secs;
	  
      granularity--;
    }
    if (granularity === 0) {
      return false;
    }
  });
  return output ? output : Drupal.t('0 sec', {}, langcode);
};

www.drupalove.com

WebNewCastle’s picture

Siddhen, thanks so much for helping out with the questions/issues here.

vaidasjokub’s picture

Hi, help someone. When I switch to lithuanian language, the timer format breaks. How to make lto timer use english format although drupal language is set to lihuanian language? I used the code for the format 00:00:00. In some internvals the timer gives an errot like this 35:35:@count[2] .
Lithuanian language use three forms - one singular and two plurals. If I understand correctly - the code should provide on more plural form? If so, how could I add one more plural form to the code?

vaidasjokub’s picture

Hi, help someone. When I switch to lithuanian language, the timer format breaks. How to make lto timer use english format although drupal language is set to lihuanian language? I used the code for the format 00:00:00. In some internvals the timer gives an error like this 35:35:@count[2] .
Lithuanian language use one singular and three plurals. If I understand correctly - the code should provide two more plural forms? If so, how could I add one more plural form to the code?