Support the ongoing development of Laravel.io →
posted 10 years ago
IOC
Last updated 2 years ago.
0

You should explain in more detail what you're trying to accomplish.

Last updated 2 years ago.
0

I want to make use of 'global logic' in my controllers (and maybe even have access to it in JavaScript). The logic would be for a 'made up date system', that's used for a game. So all the month and day names are made up and they don't follow the 24 hour, 7 day, 12 months thing.

I have not made the logic yet, but I think I will have an epoch that's based on the Unix timestamp. I can than substract the current time from the epoch and use the remaining seconds to do my calculations.

For those calculations, I want a 'global' class.

I.e.

<?php
/* Mock up!!! */
class GameTime
{
   public $months = array('Aburtei', 'Danai', 'Guura', 'Juunnu', 'Kuro', 'Serai', 'Vendrei');
   public $days = array('etc');
   private $epoch = 1398173634;
   
   public static function getMonth() 
   {
     /* Calculations etc */
	 return 'Guura';
   }
   
   public static function getDay() {}
   public static function getYear() {}
   
   public static function getFormattedDate($timestamp = time()) 
   {
     /* Calculations etc */
	 return 'Tuesday, 22 Guura, of the Year 1';
   }
   
   public static function getDateInFuture($timestamp) 
   {
     /* Calculations etc */
	 return self::getFormattedDate($timestamp);
   }
   
}
?>
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.