We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18397
    • 3,250 Posts
    This Unixtime Widget is for snippets that need to sort by a date provided in a TV. Please test these modifications. I have included a few lines before and after my changes so they will be easy to find.

    tmplvars.format.inc.php
    <?php
    				$grd->pagerClass		=$params['pclass'];
    				$grd->pagerStyle		=$params['pstyle'];
    				$o = $grd->render();
    				break;
    				
    /* Mark Kaplan unixtime modification */
    
    			case "unixtime":
    				$value = parseInput($value);  
    				// Check for MySQL style date - Adam Crownoble 8/3/2005
    				$date_match = '^([0-9]{2})-([0-9]{2})-([0-9]{4})\ ([0-9]{2}):([0-9]{2}):([0-9]{2})$';
    				$matches= array();
    				if(strpos($value,'-')!==false && ereg($date_match, $value, $matches)) {
    					$timestamp = mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[1], $matches[3]);
    				}
    				else { // If it's not a MySQL style date, then use strtotime to figure out the date
    					$timestamp = strtotime($value);
    				}
    				$o = $timestamp;
    				break;				
    
    /* END Mark Kaplan unixtime modification */
    
    			default:
    				$value = parseInput($value);
    				if($tvtype=='checkbox'||$tvtype=='listbox-multiple')
    ?>
    


    mutate_tmplvars.dynamic.action.php
    	<option value="string" <?php echo ($content['display']=='string')? "selected='selected'":""; ?>>String Formatter</option>
    	<!-- Mark Kaplan unixtime modification -->
    	<option value="unixtime" <?php echo ($content['display']=='unixtime')? "selected='selected'":""; ?>>Unixtime</option>
    	<!-- END Mark Kaplan unixtime modification -->
    </select>
    
      • 18397
      • 3,250 Posts
      UPDATE: Posted as a tutorial in the Ditto forums but I will leave this topic here so we can discuss if it is useful enough to make it into the core.
        • 22815
        • 1,097 Posts
        +1 for Core.

        Given that a part of the core distibution requires this format, it seems logical to include a widget that converts into it.
        It is much easier to say "Custom time TVs that are passed to Ditto for sorting must use the Unixtime widget" than.. whatever we say now.

          No, I don&#39;t know what OpenGeek&#39;s saying half the time either.
          MODx Documentation: The Wiki | My Wiki contributions | Main MODx Documentation
          Forum: Where to post threads about add-ons | Forum Rules
          Like MODx? donate (and/or share your resources)
          Like me? See my Amazon wishlist
          MODx "Most Promising CMS" - so appropriate!
          • 10487 MODX Staff
          • 1,535 Posts
          +1 for Core from me as well. smiley This has definitely been a frequent support request on the forums, having this widget in the core would be extremely useful.
            Garry Nutting
            Senior Developer
            MODX, LLC

            Email: [email protected]
            Twitter: @garryn
            Web: modx.com
            • 17883
            • 1,039 Posts
            +1 for core. I used this unhandy solution for doing this.
              • 25663 MODX Staff
              • 12,272 Posts
              Committing this to the core for testing as number 1254
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 8382
                • 253 Posts
                Hi, all.
                In Japanese, the expression of date is generally yyyy-mm-dd. I ask for making $date_match string an entry of a lang file.
                  • 18397
                  • 3,250 Posts
                  The $date_match string is for MySQL time only. strtotime handles everything else and it is locale friendly.
                    • 8382
                    • 253 Posts
                    I apologize to you.  I misunderstood strtotime function. lipsrsealed
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      On a couple of Dutch site I worked on I needed extensive localization, so I set the locale in the config.inc.php file. Made my life much easier.
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org