« | Main| Uncle Sam Wants Notes Developers! »

ASND Better Date-Based View Approach - Internationalized

QuickImage Category

Update: Sorry for the delay in pointing this out but as Andre notes in the comments, my modification of Sean's code is actually not necessary due to the way the code is compiled. So, forget everything I say here and just use what Sean wrote because in addition to working just fine in an international context, it is also faster.
I took Sean Burgess's post "SNTT: Date based views that don’t perform like dogs" and a subsequent suggestion in the comments about ensuring it would work for non-US date formats, and came up with a bit of sample code that show's a complete solution. You can download the code from the OpenNTF Code Bin.

Basically Sean's technique is to run a nightly agent (e.g. 12:10 AM) that revises all date-based view selection formulae so they become hard-coded for the current date. All I did was change the agent and the formula syntax so instead of a selection formula that looks like this:

ASNDtdy := [06/08/2007]; SELECT DeliveredDate = ASNDtdy

you would instead have this:

ASNDtdy := @Date(2007; 6; 8); SELECT DeliveredDate = ASNDtdy

The latter being independent of the particular mmddyyyy or ddmmyyyy date format in use, either on the server or the client. NOTE: The syntax and spacing of the first line in the formula are VERY important as that is how the agent finds the relevant views. It doesn't matter if the formula you paste in initially has the current date or not.

To see how I've modified Sean's agent, click...
So Sean's agent get's modified to look like this:
Option Public Use "OpenLogFunctions" 'Get OpenLog from OpenNTF for those wondering Sub Initialize On Error Goto ErrorHandler Dim session As New notessession Dim db As NotesDatabase tdystring = "ASNDtdy := " Set db = Session.CurrentDatabase 'change this so it loops through several dbs if you want to run one agent per server Forall v In db.Views If Left(v.SelectionFormula,Len(tdystring)) = tdystring Then v.SelectionFormula = tdystring & "@Date(" & Year(Today) & "; " & Month(Today) & "; " & Day(Today) & ")" & Strright(v.SelectionFormula,")") End If Forall c In v.Columns If Not (c.Formula = "") Then If Left(c.Formula,Len(tdystring)) = tdystring Then c.Formula = tdystring & "@Date(" & Year(Today) & "; " & Month(Today) & "; " & Day(Today) & ")" & Strright(c.Formula,")") End If End If End Forall End Forall Exit Sub ErrorHandler: Call LogError End Sub
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.

The agent has been written to use the OpenLog error handling framework (from the OpenLog OpenNTF project available here). If you don't have that enabled you'll have to rem out those lines.

I think this should work in R6 but am pretty sure R5 is out.

Comments

1 - It is not necessary to use @Date. When you save a formula, date/time constants are converted to an internal binary representation that is locale-neutral. Since the formula code is immediately compiled by the same system that generated the string, just slapping brackets around the default string conversion of the date should work just fine -- and it's more efficient than having to evaluate an @Function with multiple args for every document processed.

2 - Great tipp! I will build it into the next release of !!HELP!!

Your Host

KevinPettitt.jpg
Kevin Pettitt View Kevin Pettitt's profile on LinkedIn

Tools I Use

Idea Jam

Subscribe to This Blog

 Full Posts  Comments

MyYahoo
netvibes Add to Netvibes

Contact

Hosted by

OpenNTF

Disclaimer

This site is in no way affiliated, endorsed, sanctioned, supported, nor blessed by Lotus Software nor IBM Corporation, nor any of my past or future clients (although they are welcome to do so). The opinions, theories, facts, etc. presented here are my own and in no way represent any official pronouncement by me on behalf of any other entity.

© 2005-2017 Kevin Pettitt - all rights reserved as listed below.

Creative Commons License
Unless otherwise labeled by its originating author, the content found on this site is made available under the terms of an Attribution / NonCommercial / ShareAlike