The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

lnorth (6) [Avatar] Offline
#1
#2 fails when the default time zone is not GMT. Preceding #2 with
TimeZone.default =  TimeZone.getTimeZone('GMT')
corrects the problem.
Mittie (397) [Avatar] Offline
#2
in the latest version, the code is

def tz = TimeZone.getTimeZone('GMT')
def format = 'd MMM YYYY HH:mm:SS z'
out = "Date is ${date.format(format, tz)} !"

assert out == 'Date is 1 Jan 1970 00:00:00 GMT !'

Does that work for you?

thanks for posting
Dierk
lnorth (6) [Avatar] Offline
#3
No. It's this snippet from v17 that fails:


import static java.util.Calendar.*

def date = new Date(0)
def dateMap = [y:date[YEAR]-1900, m:date[MONTH], d:date[DAY_OF_MONTH]]
def out = "Year $dateMap.y Month $dateMap.m Day $dateMap.d" //#2
assert out == 'Year 70 Month 0 Day 1'



With default TimeZone ID America/Chicago, the Groovy Console output is:

Assertion failed: 

assert out == 'Year 70 Month 0 Day 1'
       |   |
       |   false
       Year 69 Month 11 Day 31


	at ConsoleScript7.run(ConsoleScript7:6)
Mittie (397) [Avatar] Offline
#4
ok, got it.

thanks a lot
Dierk
lnorth (6) [Avatar] Offline
#5
Listing 8.18 has a similar problem.
Mittie (397) [Avatar] Offline
#6
Yes, I see.
But I would say that we leave listing 8.18 as is because setting the timezone would just distract from the explanation of categories.

But it is anyway a good finding.
Keep them coming!

thanks for posting
Dierk