Welcome Guest, Not a member yet? Register   Sign In
DateMath
#1

[eluser]Nabeel[/eluser]
Hey everyone!

My first post and contribution Smile

I wrote my own little "toolkit" which has been working great for me (never looking at CI before, but the way I did modules, etc, URL rewriting is almost close to CI, instead of regular expressions, I map array elements to URL segments, but I digress), but learning CI now for work, and decided to port a few of the classes I wrote over to libraries, since I end up using them, and it's useful.

I haven't searched to see if it's available already, if it is, well, that's ok Smile

This one does basic math on dates - you can pass it date/time (in the MySQL format, timestamp, plain text), and it can do:

Code:
$this->datemath->add_time($time1, $time2)
$this->datemath->get_weeks_between($start, $end)
$this->datemath->get_days_from_date($start)
$this->datemath->get_days_between($start, $end)
$this->datemath->get_months_since_date($start)
$this->datemath->get_months_in_range($start, $end)

It's useful in doing things like "You posted 2 weeks ago".
You can check it out here: http://api.phpvms.net/index.php/datetest
For example, "Start" enter January 31st, and "End" enter "Today".
I entered "Yesterday" and "Today":

Quote:There are 1 months in range: Mar 2009
There are 1 days in between those two dates
There are 0.14 weeks in between those two dates

add_time() will add two times together (ie, 1:50 + 1:50 = 3:40, not 3:00)

And you can download it from here:
http://nsslive.net/downloads/ci_datemath.zip

It includes the above "datetest" controller, which shows how to use it.

I guess I need to write an article in the wiki on use.
Let me know of any bugs; I've been using it on a few projects and seemed to have fixed most of the kinks.

I have a charting library as well, based on pChart, which falls back on GoogleCharts if GD isn't found, would anyone be interested in that?
#2

[eluser]quasiperfect[/eluser]
thanks will test it out
i'm interested in the charts lib, please post it
#3

[eluser]Nabeel[/eluser]
Cool!

I'm working on converting it to the CI format, gotta see where to put the pChart stuff
#4

[eluser]jdfwarrior[/eluser]
camel case blah.
#5

[eluser]Nabeel[/eluser]
[quote author="jdfwarrior" date="1237913335"]camel case blah.[/quote]
What's wrong with camel case?
#6

[eluser]jdfwarrior[/eluser]
[quote author="Nabeel" date="1237920131"][quote author="jdfwarrior" date="1237913335"]camel case blah.[/quote]
What's wrong with camel case?[/quote]

Actually nothing, more personal preference than anything. That and I just try to follow the style guide to keep everything uniform. Style guide doesn't recommend it.


Pulled from the style guide..

Examples of improper and proper method naming:
Code:
INCORRECT:
function fileproperties() // not descriptive and needs underscore separator
function fileProperties() // not descriptive and uses CamelCase
function getfileproperties() // Better! But still missing underscore separator
function getFileProperties() // uses CamelCase
function get_the_file_properties_from_the_file() // wordy

CORRECT:
function get_file_properties() // descriptive, underscore separator, and all lowercase letters
#7

[eluser]Nabeel[/eluser]
Gotcha, I can change those. I've been using CC for years, just habit Big Grin
#8

[eluser]jdfwarrior[/eluser]
Aint got to change them on my account. Like I said for me its personal preference and just conformity. Can do whatever you like.
#9

[eluser]Nabeel[/eluser]
Well, I'd rather stay within the style guide, I haven't noticed that before




Theme © iAndrew 2016 - Forum software by © MyBB