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

[eluser]siwymilek[/eluser]
Hi,
i have a problem.I got a class which change string time to relative time, ye?

Class working propely outside CI, but inside return error's:
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: 1

Filename: libraries/relative.php

Line Number: 7

A PHP Error was encountered

Severity: Notice

Message: Undefined index: 1

Filename: libraries/relative.php

Line Number: 25

A PHP Error was encountered

Severity: Notice

Message: Undefined index: 2

Filename: libraries/relative.php

Line Number: 26

A PHP Error was encountered

Severity: Notice

Message: Undefined index: 1

Filename: libraries/relative.php

Line Number: 42
#2

[eluser]siwymilek[/eluser]
my class:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Relative {
function data( $data ) {
$r = explode(',', trim($data));
    
    $godz = $r['1'];
    
    $z = explode('.', $r['0']);
    
    
    // now data
    $ndata = date('d.m.Y, H:i');
    
    $g = explode(',', trim($ndata));
    
    $ngodz = $g['1'];
    
    $b = explode('.', $g['0']);
        
    // data arrays
    
    $relative = array(
        'dzien' => $z['0'],
        'miesiac' => $z['1'],
        'rok' => $z['2']
    );
    
    $now = array(
        'dzien' => $b['0'],
        'miesiac' => $b['1'],
        'rok' => $b['2'],
    );
    
    
    // time arrays
    $g1 = explode(':', $godz);
    $g2 = explode(':', $ngodz);
    
    $relativeTime = array(
        'godzina' => $g1['0'],
        'minuta' => $g1['1']
    );
    
    $nowTime = array(
        'godzina' => $g2['0'],
        'minuta' => $g2['1']
    );
    
    $ileMinelo = array(
        'lata' => $now['rok'] - $relative['rok'],
        'miesiace' => $now['miesiac'] - $relative['miesiac'],
        'dni' => $now['dzien'] - $relative['dzien'],
        'godziny' => $nowTime['godzina'] - $relativeTime['godzina'],
        'minuty' => $nowTime['minuta'] - $relativeTime['minuta']
    );
    
    if($ileMinelo['lata'] == 0) {
        if($ileMinelo['miesiace'] == 0) {
            if($ileMinelo['dni'] == 0) {
                if($ileMinelo['godziny'] == 0) {
                    if($ileMinelo['minuty'] == 0) {
                        return 'niecałą minutę temu';
                    } else {
                        if($ileMinelo['minuty'] == 1) {
                            return 'minutę temu';
                        } else {
                            if($ileMinelo['minuty'] == 2 || $ileMinelo['minuty'] == 3 || $ileMinelo['minuty'] == 4 || $ileMinelo['minuty'] == 22 || $ileMinelo['minuty'] == 23 ||$ileMinelo['minuty'] == 24 || $ileMinelo['minuty'] == 32 || $ileMinelo['minuty'] == 33 || $ileMinelo['minuty'] == 34 || $ileMinelo['minuty'] == 42 || $ileMinelo['minuty'] == 43 || $ileMinelo['minuty'] == 44 || $ileMinelo['minuty'] == 52 || $ileMinelo['minuty'] == 53 || $ileMinelo['minuty'] == 54 ) {
                                return $ileMinelo['minuty'] . ' minuty temy';
                            } else {
                                return $ileMinelo['minuty'] . ' minut temu';
                            }
                        }
                    }
                } else {
                    if($ileMinelo['godziny'] == 1) {
                        return 'godzinę temu';
                    } else {
                        if($ileMinelo['godziny'] == 2 || $ileMinelo['godziny'] == 3 || $ileMinelo['godziny'] == 4) {
                            return $ileMinelo['godziny'] . ' godziny temu, ' . $godz;
                        } else {
                            return $ileMinelo['godziny'] . ' godzin temu, ' . $godz;
                        }
                    }
                }
            } else {
                if($ileMinelo['dni'] == 1) {
                    return 'wczoraj, ' . $godz;
                } elseif($ileMinelo['dni'] == 2) {
                    return 'przedwczoraj, ' . $godz;
                } else {
                    return $ileMinelo['dni'] . ' dni temu, ' . $godz;
                }
            }
        } else {
            if($ileMinelo['miesiace'] == 1) {
                return 'miesiąc temu';
            } else {
                if($ileMinelo['miesiace'] == 2 || $ileMinelo['miesiace'] == 3 || $ileMinelo['miesiace'] == 4) {
                    return $ileMinelo['miesiace'] . ' miesiące temu, ' . $godz;
                } else {
                    return $ileMinelo['miesiace'] . ' miesięcy temu, ' . $godz;
                }
            }
        }
    } else {
        if($ileMinelo['lata'] == 1) {
            return 'rok temu';
        } else {
            if($ileMinelo['lata'] == 2 || $ileMinelo['lata'] == 3 || $ileMinelo['lata'] == 4) {
                return $ileMinelo['lata'] . ' lata temu, ' . $godz;
            } else {
                return $ileMinelo['lata'] . ' lat temu, ' . $godz;
            }
        }
    }
}
}
#3

[eluser]Johan André[/eluser]
I wrote a helper that does this.
Your code is totally unreadable since you use russian (?) variablenames...

http://ellislab.com/forums/viewthread/106557/
#4

[eluser]siwymilek[/eluser]
oh,thanks... i want use Your helper.
btw. im use Polish language, does Russian :p
#5

[eluser]Johan André[/eluser]
Oh sorry! Smile

Feel free to use it!
If you translate it to polish it would be great if you posted your date_lang.php in the original thread!
#6

[eluser]siwymilek[/eluser]
ok, but also You use English inside helper, does data_lang.php and Polish has a different syntax (exapmle: 2 days to go => za 2 dni)




Theme © iAndrew 2016 - Forum software by © MyBB