mn8 Language Reference | Index    

Date

SUMMARY: NO ATTRIBUTES  NO ELEMENTS  CONSTRUCTORS SUMMARY  OPERATORS SUMMARY  METHODS SUMMARYDETAIL: NO ATTRIBUTES  NO ELEMENTS  CONSTRUCTOR DETAILS  OPERATOR DETAILS  METHOD DETAILS

Description

Simple concept to facilitate the work with dates. Because on the World Wide Web there is no common denominator between date representation this concept has the purpose to assist the user in parsing and formatting dates. To specify the time format use a time pattern string. In this pattern, all ASCII letters are reserved as pattern letters, which are defined as the following:

        Symbol   Meaning                 Presentation        Example
        ------   -------                 ------------        -------
        G        era designator          (Text)              AD
        y        year                    (Number)            1996
        M        month in year           (Text & Number)     July & 07
        d        day in month            (Number)            10
        h        hour in am/pm (1~12)    (Number)            12
        H        hour in day (0~23)      (Number)            0
        m        minute in hour          (Number)            30
        s        second in minute        (Number)            55
        S        millisecond             (Number)            978
        E        day in week             (Text)              Tuesday
        D        day in year             (Number)            189
        F        day of week in month    (Number)            2 (2nd Wed in July)
        w        week in year            (Number)            27
        W        week in month           (Number)            2
        a        am/pm marker            (Text)              PM
        k        hour in day (1~24)      (Number)            24
        K        hour in am/pm (0~11)    (Number)            0
        z        time zone               (Text)              Pacific Standard Time
        '        escape for text         (DelimiMerlinter)
        ''       single quote            (Literal)           '

For day and month representation, the Date concept uses the default locale. if other locales are desired the equivalent methods can be used, methods that allow the specification of a particular desired locale.

Usage

Displaing the current date

            print Date.getToday.toTXT
            -- the result is --
            Tue Apr 23 12:28:40 EEST 2002

Parsing and reformating a date

            $date = Date.create("MMM d, ''yy", "July 10, '96")
            PRINT $date.getDate("EEE, d MMM yyyy")
            -- the result is --
            Wed, 10 Jul 1996

Version: 0.1
Authors:Remus Pereni (http://neuro.nolimits.ro)
Szabo Csaba ()
Location:http://mappa.mundi.net/spacemapper/repos/concepts/Date/
Inherits: Concept

Constructor List

create (Integer date)
create (String $pattern, String $date)
create (String $pattern, Locale $locale, String $date)
top

Operator List

Logical< (Date $when)
Logical> (Date $when)
Logical== (Date $when)
top

Method List

StringgetDate (String $pattern)
StringgetDate (String $pattern, Locale $locale)
IntegergetTime
static DategetToday
setDate (Integer $date)
setDate (String $pattern, String $date)
setDate (String $pattern, Locale $locale, String $date)
StringtoTXT
StringtoXML
top
Methods inherited from: Concept
cloneConcept, extendsConcept, fromXML, getAllInheritedConcepts, getConceptAttribute, getConceptAttributeField, getConceptAttributeFields, getConceptAttributes, getConceptConstructors, getConceptElement, getConceptElementField, getConceptElementFields, getConceptElements, getConceptLabel, getConceptMethod, getConceptMethods, getConceptOperators, getConceptType, getErrorHandler, getInheritedConcepts, getResourceURI, hasConceptAttribute, hasConceptElement, hasConceptMethod, hasPath, isHidden, loadContent, setConceptLabel, setErrorHandler, setHidden, setShowEmpty, showEmpty, toTXT, toXML, setResourceURI

Detailed Constructor Info

create (Integer date)
Parameters:
date :The value with which the new Date will be created.

Constructor which creates a new Date instance from the Integer parameter passed in. The parameter must represent the number of miliseconds after January, 1, 1970, 00:00:00 GMT.

top
create (String $pattern, String $date)
Parameters:
$pattern :The pattern for the given date.
$date :The value with which the new Date will be created.

Constructor which creates a new Date instance by parsing the value of the date using the parse rule defined by the pattern. The pattern can be formated using the date attoms.

top
create (String $pattern, Locale $locale, String $date)
Parameters:
$pattern :The pattern for the date to set.
$locale :The locale which the Date will use to represent the date. Country specific values for day, month and so on.
$date :The new date to be set.

Creates a new Date instance by parsing the value of the $date String using the parse rule defined by the $pattern parameter. The pattern date format atoms described at the top of this page.

The $locale parameter specifies that the values of the pattern atoms will be expected to conform with the proper locale parameter.

This method is especially useful when the date we want to parse is in a format different than the one specified by our own locale. In other words, usually if you try to parse a date containing textual month or day representation form other countries.

        $val = "(Miercuri) 17 Septembrie 2002"  ## a date value in Romania
                                                ## containing the day (Miercuri) and
                                                ## the month Septembrie == September 

        ## we parse the date into a date concept specifying that the value 
        ## will be conform to the Romanian locale
        $date = Date.create("(EEEEE) dd MMMM yyyy", Locale.create("RO", "ro"), $val)
        print $date
        -- the result is --
        Tue Sep 17 00:00:00 EEST 2002    
            

top

Detailed Operator Info

< (Date $when)
Parameters:
$when :a date.

Tests if this date is before the specified date.

Returns true if and only if the instant of time represented by this Date concept is strictly earlier than the instant represented by when; false otherwise.

top
> (Date $when)
Parameters:
$when :a date.

Tests if this date is after the specified date.

Returns true if and only if the instant of time represented by this Date concept is strictly later than the instant represented by when; false otherwise.

top
== (Date $when)
Parameters:
$when :a date.

Tests if this date is after the specified date.

Compares two dates for equality. The result is true if and only if the argument is a Date concept that represents the same point in time, to the millisecond, as this concept.

top

Detailed Method Info

getDate (String $pattern)
Parameters:
$pattern :The pattern for the returned date.
Returns: String

Returns a string representing the date value of this concept. The returned string is formated conform the specified pattern.

            $today = Date.getToday
            print $today.getDate("yyyy/MM/dd")
            -- the result is --
            2002/07/15
            

top
getDate (String $pattern, Locale $locale)
Parameters:
$pattern :The pattern for the returned date.
$locale :The locale which the Date will use to represent the date. Country specific values for day, month and so on.
Returns: String

Returns a string representing the date value of this concept. The returned string is formated conform the specified pattern with the values conforming with the given Locale.

            $date typeof Date

            # default locale (Romanian) in my case
            print $date.getDate("MMMM, dd (EEEEE) yyyy") 

            # The same date with the French locale
            print $date.getDate("MMMM, dd (EEEEE) yyyy", Locale.create("FR", "fr"))

            # The same date with the US locale
            print $date.getDate("MMMM, dd (EEEEE) yyyy", Locale.create("EN", "us"))

            # The same date with the German locale
            print $date.getDate("MMMM, dd (EEEEE) yyyy", Locale.create("DE", "de"))            
            -- the result is --
            septembrie, 18 (miercuri) 2002
            septembre, 18 (mercredi) 2002
            September, 18 (Wednesday) 2002
            September, 18 (Mittwoch) 2002
            

top
getTime
Returns: Integer

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.

                $today = Date.getToday
                print $today.getTime
                -- the result is --
                1026986843434
                

top
static getToday
Returns: Date

Returns an instance of a Date concept representing the today's date.

                $today = Date.getToday
                print $today.getDate("yyyy/MM/dd")
                -- the result is --
                2002/07/15
                

top
setDate (Integer $date)
Parameters:
$date :The new date to be set.
Returns:

Sets the date to the specified value.

            $today = Date.getToday
            print $today.getDate("yyyy/MM/dd")
            $date typeof Date
            $date.setDate($today.getTime)
            print $date.getDate("yyyy/MM/dd")
            -- the result is --
            2002/07/15
            2002/07/15
            

top
setDate (String $pattern, String $date)
Parameters:
$pattern :The pattern for the date to set.
$date :The new date to be set.
Returns:

Set the value of date by parsing the value of the date using the parse rule defined by the pattern. The pattern can be formated using the date atoms.

            $date typeof Date
            $date.setDate("yyyy/MM/dd", "2002/05/19")
            print $date.getDate("yyyy/MM/dd")
            -- the result is --
            2002/05/19
            

top
setDate (String $pattern, Locale $locale, String $date)
Parameters:
$pattern :The pattern for the date to set.
$locale :The locale which the Date will use to represent the date. Country specific values for day, month and so on.
$date :The new date to be set.
Returns:

Set the value of date by parsing the value of the $date String using the parse rule defined by the $pattern parameter. The pattern date format atoms described at the top of this page.

The $locale parameter specifies that the values of the pattern atoms will be expected to conform with the proper locale parameter.

This method is especially useful when the date we want to parse is in a format different than the one specified by our own locale. In other words, usually if you try to parse a date containing textual month or day representation form other countries.

        $val = "(Miercuri) 17 Septembrie 2002"  ## a date value in Romania
        $date typeof Date                       ## containing the day (Miercuri) and
                                                ## the month Septembrie == September 

        ## we parse the date into a date concept specifying that the value 
        ## will be conform to the Romanian locale
        $date.setDate("(EEEEE) dd MMMM yyyy", Locale.create("RO", "ro"), $val)
        print $date
        -- the result is --
        Tue Sep 17 00:00:00 EEST 2002    
            

top
toTXT
Returns: String

Returns a stream representing the simple text rendering of this concept.

                print Date.getToday.toTXT
                -- the result is --
                Thu Jul 18 13:24:08 EEST 2002
                

top
toXML
Returns: String

Returns a stream representing the XML rendering of this concept.

                print Date.getToday.toXML
                -- the result is --
                Thu Jul 18 13:24:08 EEST 2002
                

top