Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Would anyone know why the following code works correctly on Windows but not on Mac???

The CORRECT answer for today (24/11/2010) is 47, not 48 as returned on macOS, as according to ISO8601

Same on 10.5.8 and 10.6.4


// DKSwebWeek ( fm_date )

// 11_11_24 JR

// v1.1

// returns filenames for current week of diary

// also prev && end to insert into html



import java.text.SimpleDateFormat



def lPad = {it ->

st = '00' + it.toString()

return st.substring(st.length()-2, st.length())

}



dfm = new SimpleDateFormat("dd/MM/yyyy")

cal=Calendar.getInstance()

cal.setTime( dfm.parse(fm_date) )

now = cal.get(Calendar.WEEK_OF_YEAR)

cal.add(Calendar.DAY_OF_MONTH,-7)

prev = cal.get(Calendar.WEEK_OF_YEAR)

cal.add(Calendar.DAY_OF_MONTH,14)

next = cal.get(Calendar.WEEK_OF_YEAR)

prev = 'diary' + lPad(prev) + '.shtml'

next = 'diary' + lPad(next) + '.shtml'

return 'diary' + lPad(now) + '.shtml'

Edited by Guest

  • Author

No further on with why the get(Calendar.WEEK_OF_YEAR) returns differently on Mac and PC

But Tim Yates at StackOverflow provided a bit of a grooviness to this, which does work correctly


// DKSwebWeek ( fm_date )

// 11_11_24 JR

// v1.3

// returns filenames for current week of diary

// also prev && end to insert into html



Calendar.getInstance().with { cal ->

  // We want ISO Week numbers

  cal.firstDayOfWeek = MONDAY

  cal.minimalDaysInFirstWeek = 4

  cal.setTime(Date.parse('dd/MM/yyyy', fm_date ))

  //following line will only work in later groovy version

  //now = cal[ WEEK_OF_YEAR ]

  now = cal.get(Calendar.WEEK_OF_YEAR)

  cal.add(Calendar.DAY_OF_MONTH,-7)

  prev = cal.get(Calendar.WEEK_OF_YEAR)

  cal.add(Calendar.DAY_OF_MONTH,14)

  next = cal.get(Calendar.WEEK_OF_YEAR)

}

prev = "diary${"$prev".padLeft( 2, '0' )}.shtml"

next = "diary${"$next".padLeft( 2, '0' )}.shtml"

return "diary${"$now".padLeft( 2, '0' )}.shtml"

Edited by Guest

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.