Search found 15 matches

by alixaxel
Wed Mar 18, 2009 7:24 am
Forum: PHP - Theory and Design
Topic: Timezone Strategies
Replies: 68
Views: 7581

Re: Timezone Strategies

Great! I could have swear that I've tried a similar example one or two years ago and it produced inconsistent results.

Anyway, thanks for the snippet!
by alixaxel
Tue Mar 17, 2009 8:14 pm
Forum: PHP - Theory and Design
Topic: Design a sql query class
Replies: 7
Views: 965

Re: Design a sql query class

I've made something like that: // DB.php   <?php   class DB {     public $connection = null;       function __construct()     {         require_once(BASE_DIR . '/application/config/' . __CLASS__ . '.php');     }       function __destruct()     {         $this->Disconnect();     }       function Conn...
by alixaxel
Tue Mar 17, 2009 7:56 pm
Forum: PHP - Theory and Design
Topic: Timezone Strategies
Replies: 68
Views: 7581

Re: Timezone Strategies

Kai in your example the original timestamp is in UTC but in real world scenarios that's not always the case, suppose for example that you want to receive the local time in NYC and display it back to the Finland user, in his local time - how you you do that? Huh? When the NYC guy views it - it's in ...
by alixaxel
Tue Mar 17, 2009 7:12 pm
Forum: PHP - Theory and Design
Topic: Timezone Strategies
Replies: 68
Views: 7581

Re: Timezone Strategies

Kai in your example the original timestamp is in UTC but in real world scenarios that's not always the case, suppose for example that you want to receive the local time in NYC and display it back to the Finland user, in his local time - how you you do that? This is how I go around it:   <?php   echo...
by alixaxel
Tue Mar 17, 2009 8:40 am
Forum: PHP - Theory and Design
Topic: Timezone Strategies
Replies: 68
Views: 7581

Re: Timezone Strategies

I'm slow and bad at reading English so I do not feel like reading Wikipedia. Can someone answer to this. My friend from NYC is GMT-5 and I am GMT+2 so I am 7 hours ahead of his time, but now, however, he went to summer time so is he UTC-4 while I am UTC+2? Or in other words, is he GMT-5+DST and I a...
by alixaxel
Mon Mar 16, 2009 8:23 pm
Forum: PHP - Theory and Design
Topic: Timezone Strategies
Replies: 68
Views: 7581

Re: Timezone Strategies

- MySQL's timestamp format is not compatible with Unix/Epoch, so a tool to flip to/from that might help? - The same as all of the above, but takes Unix/Epoch timestamps as the input parameter instead of strings Anyone have code for those? :) MySQL to PHP $php = strtotime($mysql); PHP to MySQL $mysq...
by alixaxel
Mon Mar 16, 2009 7:26 pm
Forum: PHP - Theory and Design
Topic: Timezone Strategies
Replies: 68
Views: 7581

Re: Timezone Strategies

since this is not the case let me just say that GMT does have DST, and GMT is different from UTC (this one is DST-free). I guess that is incorrect then. Great, I would be confused otherwise :) No, like Andre D very well said, UTC expresses timezones and it's respective summer/winter times as offset...
by alixaxel
Mon Mar 16, 2009 7:07 am
Forum: PHP - Theory and Design
Topic: Timezone Strategies
Replies: 68
Views: 7581

Re: Timezone Strategies

This is a hard problem, specially if you want to maintain (and convert) the correct time between Timezones/DST, but since this is not the case let me just say that GMT does have DST, and GMT is different from UTC (this one is DST-free). Really? UTC does not "include" DST? As far as my res...
by alixaxel
Fri Mar 13, 2009 10:31 am
Forum: PHP - Theory and Design
Topic: Where would you start your order number iteration at?
Replies: 35
Views: 4414

Re: Where would you start your order number iteration at?

That's a lot of fuss over something so insignificant. I'm curious to know if anyone has actually had a client willing to spend time and money on you actually developing that, *just* for an order number. Agreed, this went from a simple auto-increment value to a complex check digit algorithm and fina...
by alixaxel
Fri Mar 13, 2009 9:47 am
Forum: PHP - Theory and Design
Topic: Where would you start your order number iteration at?
Replies: 35
Views: 4414

Re: Where would you start your order number iteration at?

Both implementations work, but I aimed for better performance. :D If you are looking for performance, I'm sure that the following changes would make the execution faster:   /* I prefer using the str_split()/foreach() combination for better code readability, but you can change to for() to further im...
by alixaxel
Thu Mar 12, 2009 11:15 pm
Forum: PHP - Theory and Design
Topic: Where would you start your order number iteration at?
Replies: 35
Views: 4414

Re: Where would you start your order number iteration at?

I've modified my code in order to reflect the changes in my previous topic, here is my implementation (you can also try it @ http://codepad.org/vNjgkgAu ):   <?php   class Verhoeff {     public $d = null;     public $inv = null;     public $p = null;       function __construct()     {         $this-...
by alixaxel
Thu Mar 12, 2009 8:18 pm
Forum: PHP - Theory and Design
Topic: Where would you start your order number iteration at?
Replies: 35
Views: 4414

Re: Where would you start your order number iteration at?

Nice implementation, given the example in my previous post I would suggest two things:   <?php   $id = 1337;   // returns the whole number (13375) instead of just the check digit (5) verhoeff::calculate($id);   // returns 133758, same as doing verhoeff::calculate($id . verhoeff::calculate($id)); ver...
by alixaxel
Thu Mar 12, 2009 6:51 pm
Forum: PHP - Theory and Design
Topic: Where would you start your order number iteration at?
Replies: 35
Views: 4414

Re: Where would you start your order number iteration at?

ORDER # - (ID #) 1 - 1 5 2 - 2 7 3 - 3 6 ... 42 - 42 0 ... 1337 - 1337 5 Hmm, so it adds a random number into the end? This means the order ID is unique, but also too small for the first orders, which I think the OP wants to avoid? Nope, the last digit is not a random number, it's a unique check di...
by alixaxel
Thu Mar 12, 2009 9:44 am
Forum: PHP - Theory and Design
Topic: Timezone Strategies
Replies: 68
Views: 7581

Re: Timezone Strategies

This is a hard problem, specially if you want to maintain (and convert) the correct time between Timezones/DST, but since this is not the case let me just say that GMT does have DST, and GMT is different from UTC (this one is DST-free).
by alixaxel
Thu Mar 12, 2009 9:18 am
Forum: PHP - Theory and Design
Topic: Where would you start your order number iteration at?
Replies: 35
Views: 4414

Re: Where would you start your order number iteration at?

Good topic, I enjoyed reading this discussion. If you want a short ID, that is easy to write (or spell over the phone) and gives a little more credibility to your orders I suggest that you implement a check digit function, I personally use the Verhoeff algorithm all the time since it only adds a sin...