Skip to main content

This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRIS, see the InterSystems IRIS Adoption Guide and the InterSystems IRIS In-Place Conversion Guide, both available on the WRC Distributions page (login required).

Previous sectionNext section

Setting an Expiration Date

For an expiration date, we are going to use one year from today. To do so, we obtain the current date and time, from the Caché system variable $H, trim of the time portion with the leading plus operator, and add 365 to it.

Now we need to put this date into the format that the browser expects, which is a day followed by a date followed by a time in the GMT timezone. For example, at this moment it is

Tue, 15 Aug 2000 14:16:33 GMT
Copy code to clipboard

Caché does not have a function that produces a date in this precise format, but we can assemble one using various options of the $ZD function.

ClassMethod CompleteOrder()
    // For each film, update the number of tickets sold
    Set ItemList = 
    Do ItemList.Execute(OrderID)
    While ItemList.Next() {
        Set Film=##class(Cinema.Film).%OpenId(ItemList.Get("Film"))
        Set Film.TicketsSold = Film.TicketsSold 
             + ItemList.Get("AdultTickets") + ItemList.Get("ChildTickets")
        Set ItemID = ItemList.Get("ID") 
        Do Film.%Save()
        Set Film = ""
    Set ItemList = ""
    // Put a cookie on the user's computer
    Set Expires = +$H + 365 
    Set Expires = $ZD(Expires,11) _ ", " _ $ZD(Expires,2) _ " 00:00:00 GMT" 
    Set Item = ##class(Cinema.TicketItem).%OpenId(ItemID)
    Do %response.SetCookie("CacheCinemaLastCategory", 
        Item.Show.Film.Category.%Id(), Expires, "/") 
    Set Item = "" 
    // End the session
    Set %session.EndSession = 1
Copy code to clipboard