Click here to Skip to main content
14,541,715 members

Welcome to the Lounge


For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
GeneralRe: Programming Quiz Pin
ZurdoDev6-Nov-19 2:12
mveZurdoDev6-Nov-19 2:12 
GeneralRe: Programming Quiz Pin
Jane's Diary7-Nov-19 11:22
MemberJane's Diary7-Nov-19 11:22 
GeneralRe: Programming Quiz Pin
Fernando Takeshi Sato6-Nov-19 12:08
professionalFernando Takeshi Sato6-Nov-19 12:08 
GeneralRe: Programming Quiz Pin
PIEBALDconsult5-Nov-19 9:16
professionalPIEBALDconsult5-Nov-19 9:16 
GeneralRe: Programming Quiz Pin
EliaMelfior6-Nov-19 0:34
MemberEliaMelfior6-Nov-19 0:34 
GeneralRe: Programming Quiz Pin
Stuart Dootson6-Nov-19 1:50
professionalStuart Dootson6-Nov-19 1:50 
GeneralRe: Programming Quiz Pin
Jörgen Andersson6-Nov-19 2:01
professionalJörgen Andersson6-Nov-19 2:01 
GeneralRe: Programming Quiz Pin
Stuart Dootson6-Nov-19 2:39
professionalStuart Dootson6-Nov-19 2:39 

Jörgen Andersson wrote:
shouldn't it be Data.Time.Calendar.Gregorian instead of Data.Time.Calendar.Julian

You're quite right - and that's my mistake, getting Gregorian/Julian mixed up! Gregorian is actually the default, baked into Data.Time.Calendar, while Julian is the add-on...
import Data.List.Split
import Data.Time.Calendar;
import Data.Time.Calendar.Compat;
import Text.Printf

printMonth :: Integer -> Int -> IO ()
printMonth year month = printWeeks entriesInMonth
        -- printWeeks chunks the month's entries into weeks & prints each week on a new line
        printWeeks days = mapM_ (putStrLn.unwords) (chunksOf 7 days)

        -- entriesInMonth concatenates the empty entries at the start of the month with the days
        entriesInMonth = startPadding ++ daysOfMonth

        -- daysOfMonth generates a list of days of the month as strings
        daysOfMonth = map (printf "%2d") [1..(gregorianMonthLength year month)]

        -- startPadding generates blank strings for each empty entry before day '1'
        startPadding = replicate blanksBeforeDay1 "  "

        -- blanksBeforeDay1 is the number of empty entries before day '1'
        blanksBeforeDay1 = (fromEnum $ dayOfWeek (fromGregorian year month 1)) `mod` 7

Being able to use Data.Time.Calendar rather than Data.Time.Calendar.Julian should have been a giveaway, shouldn't it Blush | :O
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

modified 6-Nov-19 8:46am.

GeneralRe: Programming Quiz Pin
Jörgen Andersson6-Nov-19 3:04
professionalJörgen Andersson6-Nov-19 3:04 
GeneralRe: Programming Quiz Pin
agolddog6-Nov-19 2:39
Memberagolddog6-Nov-19 2:39 
GeneralRe: Programming Quiz Pin
StarNamer_3-Dec-19 5:42
professionalStarNamer_3-Dec-19 5:42 
JokeShe's a witch! Pin
honey the codewitch5-Nov-19 6:41
mvahoney the codewitch5-Nov-19 6:41 
GeneralRe: She's a witch! Pin
  Forogar  5-Nov-19 7:14
professional  Forogar  5-Nov-19 7:14 
GeneralRe: She's a witch! Pin
Mike Hankey5-Nov-19 7:26
professionalMike Hankey5-Nov-19 7:26 
GeneralRe: She's a witch! Pin
jeron15-Nov-19 7:58
Memberjeron15-Nov-19 7:58 
GeneralRe: She's a witch! Pin
RickZeeland5-Nov-19 7:38
mveRickZeeland5-Nov-19 7:38 
GeneralRe: She's a witch! Pin
dandy725-Nov-19 8:09
Memberdandy725-Nov-19 8:09 
GeneralRe: She's a witch! Pin
Caslen5-Nov-19 22:40
MemberCaslen5-Nov-19 22:40 
GeneralRe: She's a witch! Pin
Super Lloyd5-Nov-19 8:26
MemberSuper Lloyd5-Nov-19 8:26 
GeneralRe: She's a witch! Pin
0x01AA5-Nov-19 8:34
mve0x01AA5-Nov-19 8:34 
GeneralRe: She's a witch! Pin
kmoorevs5-Nov-19 11:43
Memberkmoorevs5-Nov-19 11:43 
Nelek5-Nov-19 5:17
protectorNelek5-Nov-19 5:17 
GeneralRe: DUMB AI Pin
Rick York5-Nov-19 6:00
mveRick York5-Nov-19 6:00 
GeneralRe: DUMB AI Pin
BillWoodruff5-Nov-19 21:42
mveBillWoodruff5-Nov-19 21:42 
GeneralRe: DUMB AI Pin
Nelek6-Nov-19 3:42
protectorNelek6-Nov-19 3:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.