By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,741 Members | 1,973 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,741 IT Pros & Developers. It's quick & easy.

Inherit Date Class?

P: n/a
Hi,

I'm kind of new to the more involved workings of javascript, and am
having a few problems.

My problem is this: I am working with a CMS which is including various
javascrip files in the pages, including files for a calendar
(Dynarch).

I would like to add some new functionality to the CMS and add some
extra javascript files from a different calendar (Zapatech). The
Zapatech calendar is veeeeeeery closely based on the Dynarch calendar.

Both calendars extend the Date object, and in many places use the same
prototype function names e.g. Date.prototype.getMonthDays

The problem is that calling Date.getMonthDays, for example, calls the
definition from the Dynarch files (these files are included in the
page first), whereas I want it to call the definition in the Zapatech
files.

I have been looking for a way to apply appropriate namespacing, via
inheriting the Date class into a new class e.g. ZDate, but have not
figured out how to successfully achieve this.

For example, my attempts at the new ZDate class will return an error
when you try ZDate.parse("Jul 8, 2008"); stating that ZDate.parse is
not a function

So my question is how do I succesfully seperate my new javascript from
the already present definitions.

(or alternatively, is there a way to remove all the additions made to
the Date class, and start with a fresh Date version for my new
javascript?)

Any help in this is greatly appreciated!

Chris
Oct 9 '08 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Hi Chris
You will find tutorials and blog articles on what you need at
http://developer.yahoo.com/yui/theater/
Peter
"Chris" <ch********************@googlemail.comwrote in message
news:2a**********************************@d1g2000h sg.googlegroups.com...
Hi,

I'm kind of new to the more involved workings of javascript, and am
having a few problems.

My problem is this: I am working with a CMS which is including various
javascrip files in the pages, including files for a calendar
(Dynarch).

I would like to add some new functionality to the CMS and add some
extra javascript files from a different calendar (Zapatech). The
Zapatech calendar is veeeeeeery closely based on the Dynarch calendar.

Both calendars extend the Date object, and in many places use the same
prototype function names e.g. Date.prototype.getMonthDays

The problem is that calling Date.getMonthDays, for example, calls the
definition from the Dynarch files (these files are included in the
page first), whereas I want it to call the definition in the Zapatech
files.

I have been looking for a way to apply appropriate namespacing, via
inheriting the Date class into a new class e.g. ZDate, but have not
figured out how to successfully achieve this.

For example, my attempts at the new ZDate class will return an error
when you try ZDate.parse("Jul 8, 2008"); stating that ZDate.parse is
not a function

So my question is how do I succesfully seperate my new javascript from
the already present definitions.

(or alternatively, is there a way to remove all the additions made to
the Date class, and start with a fresh Date version for my new
javascript?)

Any help in this is greatly appreciated!

Chris
Oct 9 '08 #2

P: n/a
Peter McMurray wrote:
Hi Chris
You will find tutorials and blog articles on what you need at
http://developer.yahoo.com/yui/theater/
The Grady Booch video is good.

Some good quotes:

"Microsoft Office will one day consume all the bits in the universe."

And this one:
| The wrong architectural setup that I see in some places is where you
| have an architectural group over here (waves hand) not associated with
| any one project and you end up with people who are generally the
| people who are... they're there because they aren't good enough to be
| on a real project, I'll politely say.
|
| And furthermore, they are so disjointed from the real problem, that
| they're building things that nobody will care about anymore.
|

That sounds a lot like the role of the YUI team, the Yahoo Exceptional
Performance Team, and Douglas Crockford.

Points taken:
The major factor that impacts the performance of a project (its
success) is complexity
A bad process increases complexity, a good one reduces it.

But the yahoo video controls have a lot of problems (kept popping up
favorites)

Then when I try and fast forward it takes me to a login page.
Peter
"Chris" <ch********************@googlemail.comwrote in message
news:2a**********************************@d1g2000h sg.googlegroups.com...
>Hi,

I'm kind of new to the more involved workings of javascript, and am
having a few problems.

My problem is this: I am working with a CMS which is including various
javascrip files in the pages, including files for a calendar
(Dynarch).

I would like to add some new functionality to the CMS and add some
extra javascript files from a different calendar (Zapatech). The
Zapatech calendar is veeeeeeery closely based on the Dynarch calendar.

Both calendars extend the Date object, and in many places use the same
prototype function names e.g. Date.prototype.getMonthDays

The problem is that calling Date.getMonthDays, for example, calls the
definition from the Dynarch files (these files are included in the
page first), whereas I want it to call the definition in the Zapatech
files.

I have been looking for a way to apply appropriate namespacing, via
inheriting the Date class into a new class e.g. ZDate, but have not
figured out how to successfully achieve this.

For example, my attempts at the new ZDate class will return an error
when you try ZDate.parse("Jul 8, 2008"); stating that ZDate.parse is
not a function
Did you call it before it was available? Before the script containing
|ZDate.parse| was loaded?
>So my question is how do I succesfully seperate my new javascript from
the already present definitions.

(or alternatively, is there a way to remove all the additions made to
the Date class, and start with a fresh Date version for my new
javascript?)

Any help in this is greatly appreciated!

Chris
Oct 9 '08 #3

P: n/a
dhtml wrote:
Peter McMurray wrote:
And this one:
| The wrong architectural setup that I see in some places is where you
| have an architectural group over here (waves hand) not associated with
| any one project and you end up with people who are generally the
| people who are... they're there because they aren't good enough to be
| on a real project, I'll politely say.
|
| And furthermore, they are so disjointed from the real problem, that
| they're building things that nobody will care about anymore.
|

That sounds a lot like the role of the YUI team, the Yahoo Exceptional
Performance Team, and Douglas Crockford.
(not to discredit any of them, more to what I see as that organizational
role at Yahoo).
Oct 9 '08 #4

P: n/a
Hi,

Thanks for the link. Just to be clear, you were referring to the
videos by Douglas Crockford "The JavaScript Programming Language",
right?

I will try and get through the 2hours of video tonight, but in the
meantime, I would appreciate it if anyone could make a comment on what
I'm trying to achieve - whether it's incredibly easy to do, whether
it's just not possible etc.

Thanks
Oct 9 '08 #5

P: n/a
In comp.lang.javascript message <2aad5f4d-8f31-4f8f-b4a6-22f9ab07379c@d1
g2000hsg.googlegroups.com>, Wed, 8 Oct 2008 21:34:18, Chris <christopher
..jo********@googlemail.composted:
>My problem is this: I am working with a CMS which is including various
javascrip files in the pages, including files for a calendar
(Dynarch).

I would like to add some new functionality to the CMS and add some
extra javascript files from a different calendar (Zapatech). The
Zapatech calendar is veeeeeeery closely based on the Dynarch calendar.

Both calendars extend the Date object, and in many places use the same
prototype function names e.g. Date.prototype.getMonthDays
Is there anything that might reasonably be added to Date Objects, by
such systems, that one cannot readily add oneself, guided by freely-
available code and other resources?

I suppose I am assuming that you are using only Gregorian or Julian
dates, AD/BC/astro - not AM, AH, AUC, etc., dates?

If you do use imported libraries, make careful full-range checks. If MS
cannot get things right, should one expect that others will? Perhaps
that had better not be answered.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Oct 9 '08 #6

P: n/a
Hi,

I tried the implementation described above for inheritence, followed
by:

var d = ZDate.parse("Jul 8, 2005");

but I still get the same error of "ZDate.parse is not a function"

I'm sure I'm not understanding things properly (I am going to go and
watch several hours of video now to try and catch up), but in the
meantime, can I inherit from the Date prototype (or whatever) such
that ZDate.parse is actually a function (without explicitly defining
it)? Is this possible?

Thanks
Oct 10 '08 #7

P: n/a
Chris wrote on 10 okt 2008 in comp.lang.javascript:
I tried the implementation described above for inheritence,
Above what?

[please always quote on usenet]
followed
by:

var d = ZDate.parse("Jul 8, 2005");

but I still get the same error of "ZDate.parse is not a function"
You should use Date, not ZDate.

Date.parse(dateVal)
Parses a string containing a date, and returns the number of milliseconds
between that date and midnight, January 1, 1970.

Try:

<script type='text/javascript'>

alert( Date.parse('Jul 8, 2005') )

</script>

I'm sure I'm not understanding things properly (I am going to go and
watch several hours of video now to try and catch up), but in the
meantime, can I inherit from the Date prototype (or whatever) such
that ZDate.parse is actually a function (without explicitly defining
it)? Is this possible?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 11 '08 #8

P: n/a
In comp.lang.javascript message <Xn********************@194.109.133.242>
, Sat, 11 Oct 2008 13:23:31, Evertjan. <ex**************@interxnl.net>
posted:
>You should use Date, not ZDate.

Date.parse(dateVal)
Parses a string containing a date, and returns the number of milliseconds
between that date and midnight, January 1, 1970.
Accurate citation of inaccurate material.

(A) Midnight is generally, or at least often, considered as being at the
end of the day. Granted, anyone intelligent enough to become a
successful programmer will realise that; but many others visit here.

(B) Needs GMT, UTC, or ideally UT.

Epoch is 1970-01-01T00:00:00Z. I'd have transposed the "arguments" of
'between', too.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Oct 11 '08 #9

P: n/a
Dr J R Stockton wrote on 11 okt 2008 in comp.lang.javascript:
In comp.lang.javascript message
<Xn********************@194.109.133.242, Sat, 11 Oct 2008 13:23:31,
Evertjan. <ex**************@interxnl.netposted:
>>You should use Date, not ZDate.

Date.parse(dateVal)
Parses a string containing a date, and returns the number of
milliseconds between that date and midnight, January 1, 1970.

Accurate citation of inaccurate material.
It is from the Jscript 5.6 specs by MS.
>
(A) Midnight is generally, or at least often, considered as being at
the end of the day. Granted, anyone intelligent enough to become a
successful programmer will realise that; but many others visit here.
I would never specify "midnight" of a given date in the first place
(B) Needs GMT, UTC, or ideally UT.

I would think it gives the miliseconds difference between zero hours
local time and 1970-01-01T00:00:00Z

However as local time overhere is UTC+2 [CET summertime/DST],

The result of:

document.write( Date.parse('Jan 1, 1970')+1*60*60*1000 )

being zero amazes me,

as I would have expected zero to be the result of

document.write( Date.parse('Jan 1, 1970')+2*60*60*1000+'<br>' )
Epoch is 1970-01-01T00:00:00Z. I'd have transposed the "arguments" of
'between', too.


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 12 '08 #10

P: n/a
In comp.lang.javascript message <Xn********************@194.109.133.242>
, Sun, 12 Oct 2008 21:20:49, Evertjan. <ex**************@interxnl.net>
posted:
>Dr J R Stockton wrote on 11 okt 2008 in comp.lang.javascript:
>In comp.lang.javascript message
<Xn********************@194.109.133.242, Sat, 11 Oct 2008 13:23:31,
Evertjan. <ex**************@interxnl.netposted:
>>>You should use Date, not ZDate.

Date.parse(dateVal)
Parses a string containing a date, and returns the number of
milliseconds between that date and midnight, January 1, 1970.

Accurate citation of inaccurate material.

It is from the Jscript 5.6 specs by MS.
A notoriously chronologically-unreliable organisation. Additionally,
the string can contain a time and an optional offset.

>(A) Midnight is generally, or at least often, considered as being at
the end of the day. Granted, anyone intelligent enough to become a
successful programmer will realise that; but many others visit here.

I would never specify "midnight" of a given date in the first place
The Dutch are wise.

>(B) Needs GMT, UTC, or ideally UT.


I would think it gives the miliseconds difference between zero hours
local time and 1970-01-01T00:00:00Z
Yes.

>However as local time overhere is UTC+2 [CET summertime/DST],

The result of:

document.write( Date.parse('Jan 1, 1970')+1*60*60*1000 )

being zero amazes me,
It may be Summer in the Netherlands at present, but it was Winter on
1970/01/01.

>as I would have expected zero to be the result of

document.write( Date.parse('Jan 1, 1970')+2*60*60*1000+'<br>' )
Ditto.
Note that the parsing of date/time strings is ill-defined in ECMA &
ISO/IEC : accepting "Zondag 12 oktober 2008" is permissible.

Test, with different months, something like
Date.parse("2008/07/15 12:00 ") % 864e5 / 36e5
with/without UTC in the string.

+new Date(Date.parse(S)) == +new Date(S) // IIRC.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Oct 13 '08 #11

P: n/a
Dr J R Stockton wrote on 13 okt 2008 in comp.lang.javascript:
It may be Summer in the Netherlands at present, but it was Winter on
1970/01/01.
Thanks, I didn't remember ;-)

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 13 '08 #12

This discussion thread is closed

Replies have been disabled for this discussion.