« Your weekend moment of zen | Main| Get your vote on »

Lookups with DateTimes


A conversation today in AIM with Michael Bourak of domBulletin fame...

[10:57] Michael Bourak: Hi
[10:57] Michael Bourak: got a pb for a guru ;)
[10:57] Me: shoot
[10:58] Michael Bourak: in Lotuscript, is there a way to list all calendar entries between one date and another date ?
[10:58] Michael Bourak: assuming I don't want to iterate over the whole calendar view
[10:58] Michael Bourak: ideally would need a getAllDocumentsByKey (startdate)
[10:58] Michael Bourak: or something ;)

(click permalink for full details)

[10:59] Me: you should be able to do getAllDocumentsByKey
[10:59] Me: you just have to make sure your key is actually a NotesDateTime object
[11:00] Me: oh wait
[11:00] Me: you want a date range
[11:00] Me: lol
[11:00] Me: hrrmm
[11:00] Michael Bourak: yes ;)
[11:00] Me: try it with a date range
[11:00] Michael Bourak: and I'm not sure an event exist on startdate
[11:00] Me: make a date range object and use that as the key
[11:00] Me: it might work
[11:00] Michael Bourak: maybe an event on startdate + 2 days exists ;)
[11:00] Me: alternatively, you'll have to build a view navigator and iterate over that
[11:00] Me: but that's really fast
[11:01] Michael Bourak: but if users has say, 10000 calendar entries...
[11:01] Michael Bourak: it will be slow ;)
[11:02] Me: you don't necessarily have to iterate over every one
[11:02] Me: just between the entries that as as close as possible to your start & end date
[11:02] Me: it'll be a lot of code
[11:03] Me: I would definitely try creating a NotesDataTimeRange object...
[11:03] Me: and doing a getAllEntriesByKey with that
[11:03] Me: just to see what happens
[11:03] Michael Bourak: ok, let me try this way if this works ;)
[11:03] Michael Bourak: if this works, I owe you a beer
[11:03] Michael Bourak: ;)
[11:03] Me: lol
[11:03] Me: dude, if it works, I'll be really impressed with Westford  :)
[11:04] Michael Bourak: lol
[11:11] Michael Bourak: you know what ?
[11:11] Michael Bourak: that seems to work !!!
[11:28] Me: really?
[11:28] Me: ahahaha
[11:28] Me: awesome!
[11:42] Michael Bourak: maybe it only works on calendar views
[11:42] Michael Bourak: not sure
[11:42] Michael Bourak: but at least it works ;)

I can only find one mention of this approach on Google, almost two years ago on Codestore, by Glen Rohrer.  Strangely, Jake ended up not using the technique for his actual problem.

It strikes me that using this technique to populate a folder would be pretty trivial and extremely flexible.


Enjoy!

Comments

1 - Nathan,
Cool! Had a similar requirement/ question from another Lotus Notes user recently. It was a scenario that lent itself perfectly to an Embedded View - Show Single Category scenario (somebody picks a doctor, and all appointments for that doctor show up in the view), except the embedded view had to be a calendar view. Unfortunately, folders don't support calendar format, so the other 'normal' solution is out! Any bolts of lightning???

2 - Ranjit,

I'm in the middle of something else on my Notes 7 client, but I just tried this in Notes 8, and it works like a charm. I created a new folder, copied all the columns from my $Calendar view, pasted them in, and set the Folder to Calendar format. Then I put a couple of entries into it.

Design - Preview, it's all good.

Just for good measure, I embedded that in a form and previewed. Still okay.

This was in Notes 8 Basic.

3 - I stumbled across this on my own a long time ago and just assumed it was common knowledge. Emoticon

4 - To my absolute disgust, I find that I did not know one could do 'calendar-format' folders as well Emoticon. Should have dug further !!

5 - You will find that Jake didn't mention using it because someone else had the idea.

Tsk. Domino Designer Help (often) rules...

6 - @3 & 5 - Designer Help DOES mention that a NotesDateTimeRange object is an acceptable parameter to both .getAllDocumentsBykey and .getAllEntriesByKey. It does not mention what actually HAPPENS when you use it. Not surprising, honestly. If this was Javadoc, it wouldn't tell us either.

This is a great candidate for going in the upcoming IBM Lotus Domino Wiki site.

7 - @6 - Upcoming? It's already out there no?

8 - Crap I forgot the link:

{ Link }

9 - @8 - That Wiki isn't listed on the devWorks wikis yet.

{ Link }

10 - Thanks!! I'm working on code just now that needs this functionality and using a DateRange is much faster than individual lookups. My initial measurements are between 33% to 50% faster than doing individual date lookups. Of cause it also depends on the number of dates I lookup but there's no doubt it's faster. Great!

11 - that is cool, I have done that in the past using the full text search engine, very useful for finding the number of working days between two dates taking into account weekends and bank holidays where there are multiple countries involved and bank holidays fall on different days.

12 - It was already mentioned somewhere >> { Link }

13 - @12 - Heh. Sean never called the class by it's proper name: "NotesDateTimeRange" That's why Google didn't return it in my search.

Amusing.

Sean's one of the more creative problem solvers in the Domino community when it comes to indexing, so it doesn't surprise me that he spotted this capability over a year ago. Thanks for the pointer.

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)

11 Aug 

Hire Me 

Lotus-911-Logo.jpg

Search 

Disclaimer 

Welcome to Escape Velocity!

Opinions expressed here by Nathan T. Freeman are not necessarily those of his employer. However, there's a decent chance they are, so check with them if you really want to know.

But really... do you need that kind of validation? Are the opinions expressed here in doubt?

MiscLinks