BlueShoes Application Framework made with PHP http://www.blueshoes.org/


Packageindex Classtrees Modulegroups Elementlist Report XML Files

File: C:/usr/local/lib/php/blueshoes-4.2/core/date/Bs_Date.class.php
BlueShoes Application Framework - Date

Bs_Date

Bs_Object
   |
  +-- Bs_Date

**********************************************************************

 

private class Bs_Date extends Bs_Object

**********************************************************************
This static class provides many useful date and time methods.This is new, untested code! please test the return values of the methods you're goingto use... and make some comments in the methods you've used successfully. otherwise tell the author.there are the following ways to write dates and times:1) the unix timestampeg 982591823 for 2001-02-19 15:10:23some notes about the unix timestamp:This timestamp is a long integer containing the number of seconds between the Unix Epoch (January 1 1970)and the time specified.On systems where time_t is a 32bit signed integer, as most common today, the valid range for year is somewherebetween 1902 and 2037.Year may be a two or four digit value, with values between 0-69 mapping to 2000-2069 and 70-99 to 1970-1999.2) us datetimeeg 2001/02/19 15:10:23 (there is also mm.dd.yyyy and mm.dd.yy which makes it terrible.)3) eu datetimeeg 19.02.2001 15:10:234) sql datetimeeg 2001-02-19 15:10:235) sql timestampeg 200102191510236) mysql datetimeeg 2001-02-19 15:10:23 (actually mysql takes any special character instead of the '-'.)7) 'array'array('year'=>'2002', 'month'=>'12', 'day'=>'31', 'hour'=>'24', 'min'=>'59', 'sec'=>'59');the values are stored as strings, not numbers. this way we can have '03' instead of '3' fora month for example.the problem starts when ppl type in 19.2.01 and things like that, or don't use the expectedpunctuation like "." for eu dates and "/" for us dates.while unix treats 0-69 as year 2000 and 70-99 as year 1900, we do it different here!0-29 is considered 2000 and 30-99 is considered 1999. (because of the birthdays).i think it happens way more often that someone has to type in a birthday and just types 10.3.45instead someone typing in 10.3.45 when he means an event on 10.3.2045. anyway... please be strictand don't accept 2-digit year values from user input. reject it! this is only the fallback...todo: add functionality to let the user define the year-range himself (what is 1900 and what is2000).to make things easier, when converting from one date type to another, like from us to eu, weconvert it to a unix timestamp internally. this might be a problem for dates outside thetimestamp range (January 1 1970 - 2037) ... phew ... should we change this behavior? i think yes.dependencies: Bs_String

Authorsandrej arn <andrej@arn.li>
Version4.0.$id$
Copyrightblueshoes.org

 

Methods inherited from Bs_Object

isex, isexception, tostring, tohtml, persist, unpersist, bs_object, bbsetoutput, bbawake, bbisawake, bbxmsg, bbxfunctionstart, bbxfunctionend, bbxecho, bbxvar, bbxvardump, bbforcetrace, bbbufferstart, bbbufferget, bbbufferendflush, bbbufferendclean

Public Method Summary

void

Bs_Date()

constructor.
string

now()

returns the current datetime in us style.
string

formatUnixTimestamp([ string $style, string $unixTimestamp ])

returns a unix timestamp formatted as a datetime, eg 982591823 -> 19.02.2001 15:10:23.
string

formatArray([ string $style, string $array ])

returns a date-array formatted as a date, time or datetime.
string

getFormatForStyle([ string $style ])

takes a style definition and returns the format for it. see below.
string

formatUsDatetime([ string $style, string $usDatetime ])

returns a us datetime formatted as any datetime, eg 1999/08/27 13:39:36 -> 27.08.1999 13:39:36
string

formatEuDatetime([ string $style, string $euDatetime ])

returns a eu datetime formatted as any datetime, eg 27.8.1999 13:39:36 -> 1999/08/27 13:39:36
string

formatSqlDatetime([ string $style, string $sqlDatetime ])

returns a sql datetime formatted as any datetime, eg 1999-08-27 13:39:36 -> 27.8.1999 13:39:36
string

formatSqlTimestamp([ string $style, string $sqlTimestamp ])

returns a mysql timestamp formatted as a datetime, eg 19990827133936 -> 27.08.1999 13:39:36
string

sqlTimestampToUnixTimestamp(string $sqlTimestamp)

converts an sql timestamp into a unix timestamp. eg 20010219151023 -> 982591823
string

timeToUnixTimestamp(string $time)

converts a time into a unix timestamp. 15:10:23 -> 984665423
string

usDatetimeToUnixTimestamp(string $usDatetime)

converts a us datetime into a unix timestamp. eg 2001/02/19 15:10:23 -> 982591823
string

usDateToUnixTimestamp(string $usDate)

converts a us date into a unix timestamp. eg 2001/02/19 ->
string

usTimeToUnixTimestamp(string $usTime)

converts a us time into a unix timestamp. 15:10:23 ->
string

sqlDatetimeToUnixTimestamp(string $sqlDatetime)

converts a sql datetime into a unix timestamp. eg 2001-02-19 15:10:23 -> 982591823
string

sqlDateToUnixTimestamp(string $sqlDate)

converts a sql date into a unix timestamp. eg 2001-02-19 ->
string

sqlTimeToUnixTimestamp(string $sqlTime)

converts a sql time into a unix timestamp. 15:10:23 ->
string

euDatetimeToUnixTimestamp(string $euDatetime)

converts a eu datetime into a unix timestamp. eg 19.2.2001 15:10:23 -> 982591823
array

euDateToArray(string $euDate)

converts a eu date into an array.
array

sqlDateToArray(string $sqlDate)

converts a sql date into an array.
string

getSeparator(string $date)

tries to find the separator used in a date.
array

cleanDateArray(array $arr)

takes a date array and cleans its elements.
string

euDateToUnixTimestamp(string $euDate)

converts a eu date into a unix timestamp. eg 19.2.2001 -> 982591823
string

euTimeToUnixTimestamp(string $euTime)

converts a eu time into a unix timestamp. 15:10:23 ->
string

usDatetimeToEuDatetime([ string $usDatetime ])

converts a us datetime into a european datetime
string

usDateToEuDate([ string $usDate ])

converts a us date into a european date
string

usDatetimeToSqlDatetime([ string $usDatetime ])

converts a us datetime into a sql datetime
string

usDateToSqlDate([ string $usDate ])

converts a us date into a sql date
string

euDatetimeToUsDatetime([ string $euDatetime ])

converts a eu datetime into a us datetime
string

euDateToUsDate([ string $euDate ])

converts a eu date into a us date
string

euDatetimeToSqlDatetime([ string $euDatetime ])

converts a eu datetime into a sql datetime
string

euDateToSqlDate([ string $euDate ])

converts a eu date into a sql date
string

sqlDatetimeToUsDatetime([ string $sqlDatetime ])

converts a sql datetime into a us datetime eg '2001-02-28 20:54:23' -> '2001/02/28 20:54:23'
string

sqlDateToUsDate([ string $sqlDate ])

converts a sql date into a us date
string

sqlDatetimeToEuDatetime(string $sqlDatetime)

converts a sql datetime into a european datetime
string

sqlDateToEuDate([ string $sqlDate ])

converts a sql date into a eu date
mixed

monthStringToNumber(string $month, [ string $zeroFill ])

converts a month like 'Feb' or 'February' into a numerical month value (2).

Private Method Summary

void

monthToInt( $month, string $zeroFill)

use monthStringToNumber instead.
string

monthNumberToString(int $month, [ string $lang, string $type ])

converts a numerical month value to a string.

Private Field Summary

unknown

$_Bs_String

reference to the global pseudostatic Bs_String object.

Private Constant Summary

BS_DATE_VERSION >>4.0.$x$<< Warning: documentation is missing.

Public Method Details

Bs_Date

public void Bs_Date( )

  constructor.

Returns void


now

public string now( )

  returns the current datetime in us style.
this function is an alias for this->formatUnixTimestamp('us-1')

Returns string

current datetime in us style.


formatUnixTimestamp

public string formatUnixTimestamp( [ string $style, string $unixTimestamp ] )

  returns a unix timestamp formatted as a datetime, eg 982591823 -> 19.02.2001 15:10:23.
this method uses getFormatForStyle().

Parameter
string $style = >>'eu-2'<<
how the datetime should be returned. getFormatForStyle(). default is 'eu-2'.
string $unixTimestamp = >>NULL<<
(a unix timestamp or none. none means 'use the current date/time'.)
Returns string


formatArray

public string formatArray( [ string $style, string $array ] )

  returns a date-array formatted as a date, time or datetime.
this method uses getFormatForStyle().

Parameter
string $style = >>'eu-2'<<
how the datetime should be returned. getFormatForStyle(). default is 'eu-2'.
string $array = >>NULL<<
(none means 'use the current date/time'.)
Returns string


getFormatForStyle

public string getFormatForStyle( [ string $style ] )

  takes a style definition and returns the format for it. see below.
possible values for the $style param:'eu-1' -> dd.mm.yyyy hh:mm:ss'eu-2' -> dd.mm.yyyy hh:mm'eu-3' -> dd.mm.yyyy'eu-4' -> hh:mm:ss'eu-5' -> hh:mm'us-1' -> yyyy/mm/dd hh:mm:ss'us-2' -> yyyy/mm/dd hh:mm'us-3' -> yyyy/mm/dd'us-4' -> hh:mm:ss'us-5' -> hh:mm'sql-1' -> yyyy-mm-dd hh:mm:ss'sql-2' -> yyyy-mm-dd hh:mm'sql-3' -> yyyy-mm-dd'sql-4' -> hh:mm:ss'sql-5' -> hh:mm'ts-1' -> yyyymmddhhmmss

Parameter
string $style = >>'eu-2'<<
(see above)
Returns string


formatUsDatetime

public string formatUsDatetime( [ string $style, string $usDatetime ] )

  returns a us datetime formatted as any datetime, eg 1999/08/27 13:39:36 -> 27.08.1999 13:39:36
this method makes use of formatUnixTimestamp(), so watch out for the $style options.

Parameter
string $style = >>'eu-2'<<
how the datetime should be returned. see below. default is 'eu-2'.
string $usDatetime = >>NULL<<
a us datetime or none. none means 'use the current date/time'.
Returns string

See Also formatUnixTimestamp()

formatEuDatetime

public string formatEuDatetime( [ string $style, string $euDatetime ] )

  returns a eu datetime formatted as any datetime, eg 27.8.1999 13:39:36 -> 1999/08/27 13:39:36
this method makes use of formatUnixTimestamp(), so watch out for the $style options.

Parameter
string $style = >>'eu-2'<<
how the datetime should be returned. see below. default is 'eu-2'.
string $euDatetime = >>NULL<<
a eu datetime or none. none means 'use the current date/time'.
Returns string

See Also formatUnixTimestamp()

formatSqlDatetime

public string formatSqlDatetime( [ string $style, string $sqlDatetime ] )

  returns a sql datetime formatted as any datetime, eg 1999-08-27 13:39:36 -> 27.8.1999 13:39:36
this method makes use of formatUnixTimestamp(), so watch out for the $style options.

Parameter
string $style = >>'eu-2'<<
how the datetime should be returned. see below. default is 'eu-2'.
string $sqlDatetime = >>NULL<<
a sql datetime or none. none means 'use the current date/time'.
Returns string

See Also formatUnixTimestamp()

formatSqlTimestamp

public string formatSqlTimestamp( [ string $style, string $sqlTimestamp ] )

  returns a mysql timestamp formatted as a datetime, eg 19990827133936 -> 27.08.1999 13:39:36
this method makes use of formatUnixTimestamp(), so watch out for the $style options.

Parameter
string $style = >>'eu-2'<<
how the datetime should be returned. see below. default is 'eu-2'.
string $sqlTimestamp = >>NULL<<
a sql timestamp or none. none means 'use the current date/time'.
Returns string

See Also formatUnixTimestamp()

sqlTimestampToUnixTimestamp

public string sqlTimestampToUnixTimestamp( string $sqlTimestamp )

  converts an sql timestamp into a unix timestamp. eg 20010219151023 -> 982591823

Parameter
string $sqlTimestamp
Returns string

unix timestamp
this method required Bs_String.


timeToUnixTimestamp

public string timeToUnixTimestamp( string $time )

  converts a time into a unix timestamp. 15:10:23 -> 984665423
this function gets used by usDateToUnixTimestamp(), euDateToUnixTimestamp(), sqlDateToUnixTimestamp()because the time looks the same in all of these versions (us, eu, sql).the day, month and year of the returned timestamp will be from the current date.we are using php's built in strToTime(). hope it will get better... but should be ok for the time stuff.

Parameter
string $time
Returns string

unix timestamp


usDatetimeToUnixTimestamp

public string usDatetimeToUnixTimestamp( string $usDatetime )

  converts a us datetime into a unix timestamp. eg 2001/02/19 15:10:23 -> 982591823
we are using php's built in strToTime(). hope it will get better...

Parameter
string $usDatetime
Returns string

unix timestamp


usDateToUnixTimestamp

public string usDateToUnixTimestamp( string $usDate )

  converts a us date into a unix timestamp. eg 2001/02/19 ->
we are using php's built in strToTime(). hope it will get better...

Parameter
string $usDate
Returns string

unix timestamp


usTimeToUnixTimestamp

public string usTimeToUnixTimestamp( string $usTime )

  converts a us time into a unix timestamp. 15:10:23 ->
because the time looks the same in all versions (us, eu, sql) all these methods are using timeToUnixTimestamp().

Parameter
string $usTime
Returns string

unix timestamp

See Also timeToUnixTimestamp()

sqlDatetimeToUnixTimestamp

public string sqlDatetimeToUnixTimestamp( string $sqlDatetime )

  converts a sql datetime into a unix timestamp. eg 2001-02-19 15:10:23 -> 982591823
we are using php's built in strToTime(). hope it will get better...

Parameter
string $sqlDatetime
Returns string

unix timestamp

Throws -1

sqlDateToUnixTimestamp

public string sqlDateToUnixTimestamp( string $sqlDate )

  converts a sql date into a unix timestamp. eg 2001-02-19 ->
we are using php's built in strToTime(). hope it will get better...

Parameter
string $sqlDate
Returns string

unix timestamp

Throws bool false

sqlTimeToUnixTimestamp

public string sqlTimeToUnixTimestamp( string $sqlTime )

  converts a sql time into a unix timestamp. 15:10:23 ->
because the time looks the same in all versions (us, eu, sql) all these methods are using timeToUnixTimestamp().

Parameter
string $sqlTime
Returns string

unix timestamp

See Also timeToUnixTimestamp()

euDatetimeToUnixTimestamp

public string euDatetimeToUnixTimestamp( string $euDatetime )

  converts a eu datetime into a unix timestamp. eg 19.2.2001 15:10:23 -> 982591823
we are NOT using php's built in strToTime() because it returns wrong dates for eu dates :(at least until now, 2001/02/20. hope it will improve. so we use some own php code.for the date part, we use our own euDateToUnixTimestamp() method. then we create a us date withformatUnixTimestamp(). finally we convert the us date together with the time part to a timestampusing usDatetimeToUnixTimestamp().i have tested it and a) performance is definitely NOT an issue, and b) it works quite well, evenwith a date like "15.3.1999 10:26:10" (note the extra spaces in the middle).

Parameter
string $euDatetime
Returns string

unix timestamp


euDateToArray

public array euDateToArray( string $euDate )

  converts a eu date into an array.
this method does not use the unix-timestamp, so there is no limitation in the time range.

Parameter
string $euDate
(31.12.2002)
Returns array

Throws bool FALSE (not a valid date. eg wrong syntax, or 31.03.2002)
See Also sqlDateToArray()

sqlDateToArray

public array sqlDateToArray( string $sqlDate )

  converts a sql date into an array.
this method does not use the unix-timestamp, so there is no limitation in the time range.

Parameter
string $sqlDate
(2002-12-31)
Returns array

Throws bool FALSE (not a valid date. eg wrong syntax, or 2002-03-31)
See Also euDateToArray()

getSeparator

public string getSeparator( string $date )

  tries to find the separator used in a date.
example: 2002/12/31 => /31.12.2002 => .

Parameter
string $date
Returns string

(char)

Throws bool FALSE (nothing found)

cleanDateArray

public array cleanDateArray( array $arr )

  takes a date array and cleans its elements.
if these keys don't exist, they'll be added:'year', 'month', 'day', 'hour', 'min', 'sec'

Parameter
array $arr
(hash)
Returns array

(hash)


euDateToUnixTimestamp

public string euDateToUnixTimestamp( string $euDate )

  converts a eu date into a unix timestamp. eg 19.2.2001 -> 982591823
we are NOT using php's built in strToTime() because it returns wrong dates for eu dates :(at least until now, 2001/02/20. hope it will improve. so we use some own php code.

Parameter
string $euDate
Returns string

unix timestamp


euTimeToUnixTimestamp

public string euTimeToUnixTimestamp( string $euTime )

  converts a eu time into a unix timestamp. 15:10:23 ->
because the time looks the same in all versions (us, eu, sql) all these methods are using timeToUnixTimestamp().

Parameter
string $euTime
Returns string

unix timestamp

See Also timeToUnixTimestamp()

usDatetimeToEuDatetime

public string usDatetimeToEuDatetime( [ string $usDatetime ] )

  converts a us datetime into a european datetime

Parameter
string $usDatetime = >>''<<
Returns string

eu datetime


usDateToEuDate

public string usDateToEuDate( [ string $usDate ] )

  converts a us date into a european date

Parameter
string $usDate = >>''<<
Returns string

eu date

Throws bs_exception or -1, both is possible.

usDatetimeToSqlDatetime

public string usDatetimeToSqlDatetime( [ string $usDatetime ] )

  converts a us datetime into a sql datetime

Parameter
string $usDatetime = >>''<<
Returns string

sql datetime


usDateToSqlDate

public string usDateToSqlDate( [ string $usDate ] )

  converts a us date into a sql date

Parameter
string $usDate = >>''<<
Returns string

sql date


euDatetimeToUsDatetime

public string euDatetimeToUsDatetime( [ string $euDatetime ] )

  converts a eu datetime into a us datetime

Parameter
string $euDatetime = >>''<<
Returns string

us datetime


euDateToUsDate

public string euDateToUsDate( [ string $euDate ] )

  converts a eu date into a us date

Parameter
string $euDate = >>''<<
Returns string

us date


euDatetimeToSqlDatetime

public string euDatetimeToSqlDatetime( [ string $euDatetime ] )

  converts a eu datetime into a sql datetime

Parameter
string $euDatetime = >>''<<
Returns string

sql datetime


euDateToSqlDate

public string euDateToSqlDate( [ string $euDate ] )

  converts a eu date into a sql date

Parameter
string $euDate = >>''<<
Returns string

sql date


sqlDatetimeToUsDatetime

public string sqlDatetimeToUsDatetime( [ string $sqlDatetime ] )

  converts a sql datetime into a us datetime eg '2001-02-28 20:54:23' -> '2001/02/28 20:54:23'

Parameter
string $sqlDatetime = >>''<<
Returns string

us datetime


sqlDateToUsDate

public string sqlDateToUsDate( [ string $sqlDate ] )

  converts a sql date into a us date

Parameter
string $sqlDate = >>''<<
Returns string

us date


sqlDatetimeToEuDatetime

public string sqlDatetimeToEuDatetime( string $sqlDatetime )

  converts a sql datetime into a european datetime

Parameter
string $sqlDatetime
Returns string

eu datetime


sqlDateToEuDate

public string sqlDateToEuDate( [ string $sqlDate ] )

  converts a sql date into a eu date

Parameter
string $sqlDate = >>''<<
Returns string

eu date


monthStringToNumber

public mixed monthStringToNumber( string $month, [ string $zeroFill ] )

  converts a month like 'Feb' or 'February' into a numerical month value (2).
takes the param $month in the languages:- english en - danish da- french fr - italian it- german de - spanish es- dutch nl - portuguese ptyou don't need to "normalize" strings, eg 'février' to 'fevrier'.for details see db-table bs_kb.LangMonth.

Parameter
string $month
string $zeroFill = >>FALSE<<
if set to TRUE, the return value is a 2 char string. default is FALSE.
Returns mixed

(int 1 to 12 or string '01' to '12' depending on $zeroFill)

Throws int 0 (if not known, no match. does *not* return '00' if $zeroFill is TRUE.)

Private Method Details

monthToInt

private void monthToInt( $month, string $zeroFill )

  use monthStringToNumber instead.

Parameter
$month
Warning: documentation is missing.
string $zeroFill
Warning: documentation is missing.
Returns void


monthNumberToString

private string monthNumberToString( int $month, [ string $lang, string $type ] )

  converts a numerical month value to a string.
the following languages are supported: enexample:$month = monthNumberToString(12); //returns 'December'$month = monthNumberToString(12, 'en', $type='short'); //returns 'Dec'

Parameter
int $month
string $lang = >>'en'<<
the iso-code, default is 'en'. see above.
string $type = >>'long'<<
one of 'long' (default) or 'short'.
Returns string

Throws bool FALSE

Private Field Details

$_Bs_String

private unknown $_Bs_String

>><<

reference to the global pseudostatic Bs_String object.


Private Constant Details

BS_DATE_VERSION

define( BS_DATE_VERSION, >>4.0.$x$<< )
Case: default: case sensitive




Packageindex Classtrees Modulegroups Elementlist Report XML Files
PHPDoc 1.0beta