Convert from Cache date to MV date

130 views
Skip to first unread message

Jason Warner

unread,
Feb 23, 2011, 4:24:32 PM2/23/11
to InterSy...@googlegroups.com
Is there a standard way on the system to convert from a Cache date (ie
$piece($now(), ",", 1)) to an MV date without directly subtracting 46385
from it? I keep forgetting the amount to subtract from the Cache date
and would like to avoid magic numbers in my code.

jason

Dawn Wolthuis

unread,
Feb 23, 2011, 4:46:41 PM2/23/11
to intersy...@googlegroups.com
I look forward to the answer. I was going to play with dates in
2010.2.1 soon to see if we still need CURRENT_DATE - 46385 in sql
statements or if there is an alternative. SQL was the last place we
hard-coded that number, so we removed it from those too by adjusting
dates in an mvbasic utility before constructing our sql statements.
Are you finding a need for this outside of sql?

I don't know why you object to magic numbers, Jason. I'm thinking this
difference between the mumps and pick epoch dates should go on my
gravestone as one of the defining numbers of my life. cheers! --dawn

> --
> You received this message because you are subscribed to the Google Groups
> "InterSystems:  MV Community" group.
> To post to this group, send email to Cac...@googlegroups.com
> To unsubscribe from this group, send email to
> CacheMV-u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/CacheMV?hl=en

--
Dawn M. Wolthuis

Take and give some delight today

Jason Warner

unread,
Feb 23, 2011, 5:53:38 PM2/23/11
to InterSy...@googlegroups.com
Dawn,

We're finding it easier to "pollute" our MV code with COS as we work on
our ZEN project. I will admit that I'm addicted to the code completion
and there are some really nice macros in COS (&js<>, &html<>, etc).
Also, $zconvert(var, "O", "HTML") solves some headaches when writing
database items to web pages. Because of this, I'm finding the need to
stuff $NOW() into MV.Dates and would love to have a "standard" way of
doing this.

Jason

PS - (4 / (6 / 3)) + (8 * 5) = 42, so I guess it IS a "magic" number...
Maybe I can make it equal 23 and get it into a movie also.

Dawn Wolthuis

unread,
Feb 23, 2011, 6:04:13 PM2/23/11
to intersy...@googlegroups.com
Yeah, I could tell you decided to write source in mvbasic, cos, and
javascript for Zen. I was trying to limit the general purpose
programming languages to 2 (mvbasic and javascript) in addition to
sql, cmql, xml, html, and css. Adding cos to the mix seemed like way
too much of a learning curve for developers coming onto the project. I
wish that instead we could have &html<> and such in mvbasic, but until
then, those PRINT statements work their magic. cheers! --dawn

--

Michael Cohen

unread,
Feb 23, 2011, 8:40:15 PM2/23/11
to intersy...@googlegroups.com
Does this snippet of COS code do what you want?

#Define MVDateNow ($p($h,",",1)-46385)
w "today is: "_$$$MVDateNow

the outer parens let you use it in an expression

Peter Lynch

unread,
Feb 23, 2011, 9:34:37 PM2/23/11
to intersy...@googlegroups.com
Oh get out of here.
That is too sensible a solution!

Jason Warner

unread,
Feb 24, 2011, 11:38:53 AM2/24/11
to InterSy...@googlegroups.com
A macro is a very nice solution. Now the question is, how do I get this
macro recognized system wide? Do I have to include it in every program
or is there a way to register macros in a namespace (or better globally)
on a system?

Jason

On 2/23/2011 6:40 PM, Michael Cohen wrote:
> Does this snippet of COS code do what you want?
>
> #Define MVDateNow ($p($h,",",1)-46385)
> w "today is: "_$$$MVDateNow
>
> the outer parens let you use it in an expression
>
> -----Original Message-----
> From: intersy...@googlegroups.com [mailto:intersy...@googlegroups.com] On Behalf Of Dawn Wolthuis
> Sent: Wednesday, February 23, 2011 6:04 PM
> To: intersy...@googlegroups.com
> Subject: Re: [InterSystems-MV] Convert from Cache date to MV date
>
> Yeah, I could tell you decided to write source in mvbasic, cos, and
> javascript for Zen. I was trying to limit the general purpose
> programming languages to 2 (mvbasic and javascript) in addition to
> sql, cmql, xml, html, and css. Adding cos to the mix seemed like way
> too much of a learning curve for developers coming onto the project. I

> wish that instead we could have&html<> and such in mvbasic, but until


> then, those PRINT statements work their magic. cheers! --dawn
>
> On Wed, Feb 23, 2011 at 4:53 PM, Jason Warner<jas...@brashers.com> wrote:
>> Dawn,
>>
>> We're finding it easier to "pollute" our MV code with COS as we work on our
>> ZEN project. I will admit that I'm addicted to the code completion and there

>> are some really nice macros in COS (&js<>,&html<>, etc). Also,

Ed Clark

unread,
Feb 24, 2011, 12:18:20 PM2/24/11
to intersy...@googlegroups.com
There are class methods in class %MV.Date--DateToLogical() and LogicalToDate()--which convert an mv date number to/from a $H date number.

Jason Warner

unread,
Feb 24, 2011, 12:34:30 PM2/24/11
to InterSy...@googlegroups.com
Perfect! This was what I was looking for. If for some reason (however
unlikely) Intersystems decides to change their date format, I can still
use this in my code.

s mvDate = ##class(%MV.Date).DateToLogical($piece($now(), ",", 1))

Jason

JASON:; crt date()
15761
JASON:[ w ##class(%MV.Date).DateToLogical($piece($now(), ",", 1))
15761

aroundtuit

unread,
Feb 24, 2011, 7:59:30 PM2/24/11
to InterSystems: MV Community
For some reason the link on the notification email of this topic has a
broken link to the IS MV community forum - it takes me to the old, non-
existent one.

Also, selecting by date is simple using the internal format - SELECT
FILE WITH DATE LESS THAN "010101". What should I do when I want to
select within the date field - SELECT FILE WITH DATE CONTAINING "DEC"
for instance. Is there an elegant solution to this which does not
entail creating a symbolic of the external date?

aroundtuit

unread,
Feb 24, 2011, 8:31:11 PM2/24/11
to InterSystems: MV Community
Oh forget the second part of that post. I do have a question like
that, but that one is not it. I may get back later to it.

Ross Ferris

unread,
Feb 24, 2011, 8:45:05 PM2/24/11
to intersy...@googlegroups.com
As an outsider looking at this, I have to wonder what all of the fuss is
about .... and especially for someone like Dawn who is doing a green
fields development rather than a conversion.

I would have thought that the only time the difference in "day 0" was
significant would be when you were converting an application, and more
importantly DATA .... once the data is actually converted, I wouldn't
have thought that ANYONE would give a damn what day zero is ... provided
they could convert from "an internal date", subtract 2 dates to get a
day difference. I would have thought it would be easier all around to
simply use whatever the "natural" day 0 of the system is.

If you were shuffling data back & forth between Cache & "real" MV
systems, then I could see a case, but to have to jump through hoops like
this seems a bit lame to me

Just my $0.02

Ross Ferris
Stamina Software
Visage > Better by Design!

>>>>> On Wed, Feb 23, 2011 at 3:24 PM, Jason


>Warner<jas...@brashers.com> wrote:
>>>>>> Is there a standard way on the system to convert from a Cache
date
>>>>>> (ie $piece($now(), ",", 1)) to an MV date without directly
>>>>>> subtracting 46385 from it? I keep forgetting the amount to
>>>>>> subtract from the Cache date and would like to avoid magic
numbers in
>my code.
>>>>>>
>>>>>> jason
>>>>>>

>unsub...@googlegroups.com

Dawn Wolthuis

unread,
Feb 24, 2011, 9:28:59 PM2/24/11
to intersy...@googlegroups.com
Hi Ross -- As long as you are working within MV proper, it all works
as expected. When you do something that is simple to do in Cache'
compared to any other MV environment I've worked with, such as
performing fast SQL queries against a SQL projection generated from
the same spec (class) from which the MV DICT is generated, you start
to play in the MUMPs world a little bit -- enough to entice Jason to
go with the flow and integrate mumps code in with the pick code. That
might be a good business decision for some companies, but I try to
resist that for what I think to be some good reasons for my startup.

For example, in SQL there are CURDATE and CURRENT_DATE functions that
are documented as returning the current date. However it is the
current mumps date. So, you need to subtract the magic number.

The reason I once knew this number too well was because the projection
for AJAX/Zen did not initially work with the Zen components. So, for
example, I could not enter my birth date into the system because it
was a negative number and negative dates were not permitted (since
they are not in mumps).

The good news is that everything our team identified was addressed, so
we do very little mumps date/pick date gymnastics anymore other than
related to SQL queries with comparisons to the current date. Jason is
trying to work with pick dates through mumps code, where the utilities
are obviously directed to the mumps date instead.

I hope I said that accurately, else feel free to correct me.

So, yes, Ross, you are right that we are not caring about this
anymore, but in the evolution of the integration of MV with Zen and
SQL we have worked with this epoch date difference. --dawn

--

Jason Warner

unread,
Feb 25, 2011, 12:06:01 PM2/25/11
to InterSy...@googlegroups.com
Dawn explained it very well. The issue we have is that we have a legacy
MV system with data and information in MV format. We are trying to
"modernize" it by adding a nice web interface to our data.
Unfortunately, in Cache there are some things that you have to do in
COS. For example, in a ZenMethod, you can use &js<> tags to send
information to the client. I am not aware of a way to do this in
MVBASIC. We also find it easier to do any methods that output HTML to
the client in COS. The &html<> macros allow us to write pure HTML and
not worry about quote escaping and other headaches involved with print
statements. I didn't know there were 3 different quote characters in
MVBASIC until I had to start doing HTML in it.

Because COS adds some niceness that we don't have in MV (and in some
cases the necessity of COS), MV developers have to grapple with the date
issue. Like Dawn said, there are still some instances where you still
have to know the magic number so that you can convert what you get from
Cache to something that MV understands. Intersystems has been very good
at solving these issues, but they still crop up from time to time.

Jason

>> If you were shuffling data back& forth between Cache& "real" MV

Dawn Wolthuis

unread,
Feb 25, 2011, 12:30:03 PM2/25/11
to intersy...@googlegroups.com
Jason -- Instead of the &js<> in cos, we just do print statements in
mvbasic. We have found that we rarely need to do this, but it is
possible, just like the &html<> where we can do print statements
instead.

--dawn

--

Jason Warner

unread,
Feb 25, 2011, 12:56:29 PM2/25/11
to InterSy...@googlegroups.com
Interesting...

So you're saying instead of:

ClassMethod zenAlert(message as %String) [ZenMethod, language=cache] {
&js< alert("#(message)#"); >
}

I can do this:

ClassMethod zenAlert(message as %String) [ZenMethod, language=mvbasic] {
print \alert("\ : message : \");\
}

And that goes back to the client? I guess that makes sense since most of
the macros get translated into writes with proper escaping behind the
scenes. I just assumed there was some more wiring that ZEN added when it
encounters the &js<> macro.

jason

On 2/25/2011 10:30 AM, Dawn Wolthuis wrote:
> Jason -- Instead of the&js<> in cos, we just do print statements in


> mvbasic. We have found that we rarely need to do this, but it is

> possible, just like the&html<> where we can do print statements


> instead.
>
> --dawn
>
> On Fri, Feb 25, 2011 at 11:06 AM, Jason Warner<jas...@brashers.com> wrote:
>> Dawn explained it very well. The issue we have is that we have a legacy MV
>> system with data and information in MV format. We are trying to "modernize"
>> it by adding a nice web interface to our data. Unfortunately, in Cache there
>> are some things that you have to do in COS. For example, in a ZenMethod, you

>> can use&js<> tags to send information to the client. I am not aware of a


>> way to do this in MVBASIC. We also find it easier to do any methods that

>> output HTML to the client in COS. The&html<> macros allow us to write pure

Dawn Wolthuis

unread,
Feb 25, 2011, 4:07:14 PM2/25/11
to intersy...@googlegroups.com
I looked in some old code bz we don't have a need to do this anymore
and we are just doing things like:

print "alert('hi " : coolVariable : " mom')"

at the end of a ZenMethod.

We try to keep all of our source code mvbasic both because we have
good mvbasic experience on the team (not me, but others), so that we
are not maintaining so many languages, and because we are storing
things in mv persistent classes. InterSystems has been good about
keeping sort-of-kinda to the statement that anything you can do in cos
you can do in mvbasic. The things that are hard for us are those dang
macros. We have learned to convert most other things we find in
examples and such. We thought we had it when we got one working by
calling cos with the macro in it from mvbasic, but then the next one
we could not get to function that way, so we have a few places where
we should be employing a macro and we don't or where we should be
writing mvbasic and we are not.

--dawn

--

Reply all
Reply to author
Forward
0 new messages