|
For bonus points, on the management/sales side:
- convince a culture with a different week size to adopt the 7 days week.
- convince a culture without the concept of calendar to adopt a 10 days week calendar (or 5 day, for the impatient), and then apply previous step.
|
|
|
|
|
Took this a step further and extended the code, and it should work with culture:
void Main()
{
StringBuilder builder = new StringBuilder();
Enumerable.Range(1, 12)
.ToList()
.ForEach(e => PopulateDayOfMonth(2021, e, builder));
Console.WriteLine(builder.ToString().Trim());
}
static void PopulateDayOfMonth(int year, int month, StringBuilder builder)
{
builder.AppendLine();
int space = 6;
int dashLine = 1 + (space * 7);
IEnumerable<DateTime> days = Enumerable.Range(1, DateTime.DaysInMonth(year, month))
.Select(d => new DateTime(year, month, d));
builder.AppendLine(days.First().ToString("MMMMM"));
builder.Append('-', dashLine);
builder.AppendLine();
builder.AppendLine($"|{string.Join("|", Enum.GetNames(typeof(DayOfWeek)).Select(d => $" {d.Substring(0, 3)} "))}|" );
builder.Append('-', dashLine);
builder.AppendLine();
DayOfWeek dow = days.First().DayOfWeek;
while (dow != 0)
{
builder.Append(' ', space);
dow--;
}
bool first = true;
foreach (var d in days)
{
if (!first && d.DayOfWeek == 0)
{
builder.AppendLine("|");
builder.Append('-', dashLine);
builder.AppendLine();
}
builder.Append($"|{d.Day.ToString().PadLeft(space - 2)} ");
first = false;
}
builder.AppendLine("|");
builder.Append('-', dashLine);
builder.AppendLine();
}
With the following output:
January
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
| 1 | 2 |
-------------------------------------------
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
-------------------------------------------
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
-------------------------------------------
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
-------------------------------------------
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
-------------------------------------------
| 31 |
-------------------------------------------
February
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
| 1 | 2 | 3 | 4 | 5 | 6 |
-------------------------------------------
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
-------------------------------------------
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
-------------------------------------------
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
-------------------------------------------
| 28 |
-------------------------------------------
March
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
| 1 | 2 | 3 | 4 | 5 | 6 |
-------------------------------------------
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
-------------------------------------------
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
-------------------------------------------
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
-------------------------------------------
| 28 | 29 | 30 | 31 |
-------------------------------------------
April
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
| 1 | 2 | 3 |
-------------------------------------------
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
-------------------------------------------
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
-------------------------------------------
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
-------------------------------------------
| 25 | 26 | 27 | 28 | 29 | 30 |
-------------------------------------------
May
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
| 1 |
-------------------------------------------
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
-------------------------------------------
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
-------------------------------------------
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
-------------------------------------------
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
-------------------------------------------
| 30 | 31 |
-------------------------------------------
June
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
| 1 | 2 | 3 | 4 | 5 |
-------------------------------------------
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
-------------------------------------------
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
-------------------------------------------
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
-------------------------------------------
| 27 | 28 | 29 | 30 |
-------------------------------------------
July
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
| 1 | 2 | 3 |
-------------------------------------------
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
-------------------------------------------
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
-------------------------------------------
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
-------------------------------------------
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
-------------------------------------------
August
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
-------------------------------------------
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
-------------------------------------------
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
-------------------------------------------
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
-------------------------------------------
| 29 | 30 | 31 |
-------------------------------------------
September
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
| 1 | 2 | 3 | 4 |
-------------------------------------------
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
-------------------------------------------
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
-------------------------------------------
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
-------------------------------------------
| 26 | 27 | 28 | 29 | 30 |
-------------------------------------------
October
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
| 1 | 2 |
-------------------------------------------
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
-------------------------------------------
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
-------------------------------------------
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
-------------------------------------------
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
-------------------------------------------
| 31 |
-------------------------------------------
November
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
| 1 | 2 | 3 | 4 | 5 | 6 |
-------------------------------------------
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
-------------------------------------------
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
-------------------------------------------
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
-------------------------------------------
| 28 | 29 | 30 |
-------------------------------------------
December
-------------------------------------------
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
-------------------------------------------
| 1 | 2 | 3 | 4 |
-------------------------------------------
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
-------------------------------------------
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
-------------------------------------------
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
-------------------------------------------
| 26 | 27 | 28 | 29 | 30 | 31 |
-------------------------------------------
|
|
|
|
|
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Unfortunately, that still assumes the first day of the week is Sunday.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Sunday is part of the weekend. That's a clue as to the correct day that a week starts on
|
|
|
|
|
Member 11005478 wrote: weekend. That's a clue as to the correct day that a week starts on Just like bookends are all on one side.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Otherwise you could use Genesis 2.2 as a reference.
|
|
|
|
|
Jörgen Andersson wrote: Otherwise you could use Genesis 2.2 as a reference. Correct. The Old Testament week.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Hold up, this is implying that we need to start working Saturdays, a six work-day week.
|
|
|
|
|
The first thing that I thought as well...here in Poland, the week starts on Monday. Almost two years here and this still throws me off.
|
|
|
|
|
Pfft... I've been using an MS Word template with a macro to create calendars since the mid-90s.
With weeks beginning on Monday as per ISO and ISO week numbers as well.
|
|
|
|
|
This could be a fun little puzzle.
I just get tired thinking about solving it, i would have to search for a time library in javascript/php, and then format the output nicely.
Just not in the mood for a little puzzle, does anyone identify with this feeling sometimes?
Nice quiz though.
|
|
|
|
|
In Haskell (because, of course Haskell!):
import Data.List.Split
import Data.Time.Calendar;
import Data.Time.Calendar.Compat;
import Data.Time.Calendar.Julian;
import Text.Printf
printMonth :: Integer -> Int -> IO ()
printMonth year month = printWeeks entriesInMonth
where
-- 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..(julianMonthLength 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 (fromJulian year month 1)) `mod` 7
which gives:
> printMonth 2019 12
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
> printMonth 20190 12
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
> printMonth 20190 11
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
[ETA] That's using the Julian calendar - the standard Gregorian calendar can be used by replacing the word 'julian' or 'Julian' with 'gregorian'/'Gregorian'. And yes, I should be able to remember which calendar we use [/ETA]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
modified 6-Nov-19 8:41am.
|
|
|
|
|
So, I don't know sh*t about Haskell, but shouldn't it be Data.Time.Calendar.Gregorian instead of Data.Time.Calendar.Julian?
Unless you're living in Russia that is.
|
|
|
|
|
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
where
-- 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
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
modified 6-Nov-19 8:46am.
|
|
|
|
|
|
Checkin rejected, hard-coded values.
Just kidding, the knuckleheads I work with hard-code things all over the place, and management won't let us have any code reviews. Sigh.
|
|
|
|
|
I'd go with a Bash script...
cal
|
|
|
|
|
|
It's most curious that, as there only are two ways to plug in a USB, you should be right 50% of the time and yet...
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
There are 3 sides to a USB;
1) The side you try first
2) The wrong side
3) The Right side
They call me different but the truth is they're all the same!
JaxCoder.com
|
|
|
|
|
Irrefutable proof of the existence of other dimensions I'd say.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Looks more like FireWire to me
|
|
|
|
|
To be fair, the USB logo goes on top.
Problem is, while device manufacturers generally get it right, if a connector is mounted sideways, it becomes anyone's guess again.
|
|
|
|
|
I have a few devices where the logo on top rule doesn't apply, while not many it's enough to keep me guessing!
|
|
|
|