This document discusses strategies for calculating dates and converting between date formats. It introduces the Julian day number system for representing dates as consecutive integers. Magic formulas are presented for converting between Gregorian calendar dates and Julian day numbers. The document also describes designing a Date class that uses Julian day numbers to represent dates internally in a way that is immutable and suitable for testing. Unit tests are recommended to validate the date calculations.
Analysis on The Presentation of Evidence Between the Adversary System in Mala... Selvakumar Balakrishnan
INTRODUCTION
THE ADVERSARIAL SYSTEM IN MALAYSIA
THE INQUISITORIAL SYSTEM IN GENERAL
PRESENTATION OF EVIDENCE IN ADVERSARY SYSTEM IN MALAYSIA
PRESENTATION OF EVIDENCE IN INQUISITORIAL SYSTEM IN GENERAL
THE ADVANTAGES AND DISADVANTAGES OF ADVERSARY SYSTEM
THE ADVANTAGES AND DISADVANTAGES OF INQUISITORIAL SYSTEM
CONCLUSIONS AND RECOMMENDATIONS
When you are about to delete an object, how do you know that it is not being used in another thread?
How can you tell if the object is still alive before you trying call its member function? Is it being destructed in another thread?
Analysis on The Presentation of Evidence Between the Adversary System in Mala... Selvakumar Balakrishnan
INTRODUCTION
THE ADVERSARIAL SYSTEM IN MALAYSIA
THE INQUISITORIAL SYSTEM IN GENERAL
PRESENTATION OF EVIDENCE IN ADVERSARY SYSTEM IN MALAYSIA
PRESENTATION OF EVIDENCE IN INQUISITORIAL SYSTEM IN GENERAL
THE ADVANTAGES AND DISADVANTAGES OF ADVERSARY SYSTEM
THE ADVANTAGES AND DISADVANTAGES OF INQUISITORIAL SYSTEM
CONCLUSIONS AND RECOMMENDATIONS
When you are about to delete an object, how do you know that it is not being used in another thread?
How can you tell if the object is still alive before you trying call its member function? Is it being destructed in another thread?
A fraction (from Latin fractus, "broken") represents a part of a whole or, more generally, any number of equal parts. When spoken in everyday English, a fraction describes how many parts of a certain size there are, for example, one-half, eight-fifths, three-quarters. A common, vulgar, or simple fraction (examples: 1 2 {\displaystyle {\tfrac {1}{2}}} {\tfrac {1}{2}} and 17/3) consists of an integer numerator displayed above a line (or before a slash), and a non-zero integer denominator, displayed below (or after) that line. Numerators and denominators are also used in fractions that are not common, including compound fractions, complex fractions, and mixed numerals.
The numerator represents a number of equal parts, and the denominator, which cannot be zero, indicates how many of those parts make up a unit or a whole. For example, in the fraction 3/4, the numerator, 3, tells us that the fraction represents 3 equal parts, and the denominator, 4, tells us that 4 parts make up a whole. The picture to the right illustrates 3 4 {\displaystyle {\tfrac {3}{4}}} {\tfrac {3}{4}} or ¾ of a cake.
Help your children to learn about the area and perimeter of shapes with our bumper resource pack. Includes a variety of classroom teaching, display and activity resources to introduce the topic to your children and then extend their knowledge and skills!
Available from http://www.teachingpacks.co.uk/the-area-and-perimeter-pack/
Fraction, Decimals and Percents - Math Review JeopardyMr. Godin
I love Jeopardy. It's by far my favorite game show. I've used the Jeopardy format, including sounds, to create a unique and fun way for my students to review their math concepts.
Hi,I have implemented increment() method. Please find the below up.pdfAnkitchhabra28
Hi,
I have implemented increment() method. Please find the below updated code.
DaysBetween Class:
import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.Scanner;
class DateClass {
protected int year;
protected int month;
protected int day;
public static final int MINYEAR = 1583;
// Constructor
public DateClass(int newMonth, int newDay, int newYear)
{
month = newMonth;
day = newDay;
year = newYear;
}
// Observers
public int getYear()
{
return year;
}
public int getMonth()
{
return month;
}
public int getDay()
{
return day;
}
public int lilian()
{
// Returns the Lilian Day Number of this date.
// Precondition: This Date is a valid date after 10/14/1582.
//
// Computes the number of days between 1/1/0 and this date as if no calendar
// reforms took place, then subtracts 578,100 so that October 15, 1582 is day 1.
final int subDays = 578100; // number of calculated days from 1/1/0 to 10/14/1582 November
17, 1858
int numDays;
// Add days in years.
numDays = year * 365;
// Add days in the months.
if (month <= 2)
numDays = numDays + (month - 1) * 31;
else
numDays = numDays + ((month - 1) * 31) - ((4 * (month-1) + 27) / 10);
// Add days in the days.
numDays = numDays + day;
// Take care of leap years.
numDays = numDays + (year / 4) - (year / 100) + (year / 400);
// Handle special case of leap year but not yet leap day.
if (month < 3)
{
if ((year % 4) == 0) numDays = numDays - 1;
if ((year % 100) == 0) numDays = numDays + 1;
if ((year % 400) == 0) numDays = numDays - 1;
}
// Subtract extra days up to 10/14/1582.
numDays = numDays - subDays;
return numDays;
}
Override
public String toString()
// Returns this date as a String.
{
String monthString = new DateFormatSymbols().getMonths()[month-1];
return(monthString + \"/\" + day + \"/\" + year);
}
public class mjd
{
public int mjd()
{
final int subDays = 678941;
int numDays;
numDays = year * 365;
if (month <= 2)
numDays = numDays + (month - 1) * 31;
else
numDays = numDays + ((month -1) * 31) - ((4 * (month-1) + 27)/10);
numDays = numDays + day;
numDays = numDays + (year / 4) - (year / 100) + (year / 400);
if (month < 3)
{
if ((year % 4) == 0) numDays = numDays -1;
if ((year % 100) == 0) numDays = numDays + 1;
if ((year % 400) == 0) numDays -= numDays -1;
}
// Days subtracted up to 10/14/1582
numDays = numDays - subDays;
return numDays;
}
}
public class djd
{
public int djd()
{
final int subDays = 693961; // number of calculated days from 1/1/0 to January 1,1900
int numDays;
// Add days in years.
numDays = year * 365;
// Add days in the months.
if (month <= 2)
numDays = numDays + (month - 1) * 31;
else
numDays = numDays + ((month - 1) * 31) - ((4 * (month-1) + 27) / 10);
// Add days in the days.
numDays = numDays + day;
// Take care of leap years.
numDays = numDays + (year / 4) - (year / 100) + (year / 400);
// Handle special case of leap year but not yet leap day.
if (month < 3)
{
if ((year % 4) == 0) numDays = numDays - 1;
if ((year % 100) == 0) numDays = numDays + 1;
if ((year % .
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
As AI technology is pushing into IT I was wondering myself, as an “infrastructure container kubernetes guy”, how get this fancy AI technology get managed from an infrastructure operational view? Is it possible to apply our lovely cloud native principals as well? What benefit’s both technologies could bring to each other?
Let me take this questions and provide you a short journey through existing deployment models and use cases for AI software. On practical examples, we discuss what cloud/on-premise strategy we may need for applying it to our own infrastructure to get it to work from an enterprise perspective. I want to give an overview about infrastructure requirements and technologies, what could be beneficial or limiting your AI use cases in an enterprise environment. An interactive Demo will give you some insides, what approaches I got already working for real.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
Here is something new! In our next Connector Corner webinar, we will demonstrate how you can use a single workflow to:
Create a campaign using Mailchimp with merge tags/fields
Send an interactive Slack channel message (using buttons)
Have the message received by managers and peers along with a test email for review
But there’s more:
In a second workflow supporting the same use case, you’ll see:
Your campaign sent to target colleagues for approval
If the “Approve” button is clicked, a Jira/Zendesk ticket is created for the marketing design team
But—if the “Reject” button is pushed, colleagues will be alerted via Slack message
Join us to learn more about this new, human-in-the-loop capability, brought to you by Integration Service connectors.
And...
Speakers:
Akshay Agnihotri, Product Manager
Charlie Greenberg, Host
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Datetime - Julian Date
1. Notes on Date & TimePart 1: Date Calculation Shuo Chen Shuo Chen (blog.csdn.net/Solstice) 2010/08
2. Contents of this serial Strategic date calculation Time keeping (in UTC) Time zone and daylight saving time Choices between local time and UTC time Time in a distributed system How leap seconds affect heartbeat protocol Source Code http://github.com/chenshuo/recipes/tree/master/datetime/ 2010/08 Shuo Chen (blog.csdn.net/Solstice) 2
3. Part 1: Strategic date calculation Date calculation with Julian Day Number Assume dates after 1900 until we talk about history Illustrations of magic formulas Design a Date class Alternative designs Unit tests Libraries available Brief history of Gregorian calendar 2010/08 Shuo Chen (blog.csdn.net/Solstice) 3
4. Common date calc tasks How many days between two dates 2000-01-01 and 2008-08-08 Is 2012/01/01 a Sunday? When is the 1000th day after 2009/12/25? Would be trivial if dates map to consecutive integers and vice versa. Shuo Chen (blog.csdn.net/Solstice) 2010/08 4
5. Gregorian calendar Days in a month Leap year 97 leap years every 400 years A full cycle is 400 years, 400*365+97 = 146097d How to number each date with an integer given such an irregular pattern? 2010/08 Shuo Chen (blog.csdn.net/Solstice) 5
6. Convert Dates to Integers Day number of (year, month, day) is sum of Days before Jan 1 of the year, def daysYear() as daysYear(year+1) = daysYear(year) + 365 + isLeap(year) daysYear(2004) = daysYear(2003) + 365 daysYear(2005) = daysYear(2004) + 366 Days in this year before 1st day of this month daysMonth(1) = 0, daysMonth(2) = 31, daysMonth(3) = 28 or 29, daysMonth(4) = 31, ... Days in this month, ie. day Before going on with rolling our own … 2010/08 Shuo Chen (blog.csdn.net/Solstice) 6
7. Julian Day Number The standard method of representing dates as consecutive positive integers Some day predates all record history as day 1 4700+ BC or so Integer arithmetic only, without look-up table See http://www.faqs.org/faqs/calendars/faq/ http://en.wikipedia.org/wiki/Julian_day 2010/08 Shuo Chen (blog.csdn.net/Solstice) 7
8. Julian Day Number from Date Code in C, divisions are truncation 1 <= month <= 12, 1<= day Tons of magic numbers 2010/08 Shuo Chen (blog.csdn.net/Solstice) 8 inttoJulianDayNumber(int year, int month, int day) { int a = (14 - month) / 12; int y = year + 4800 - a; int m = month + 12 * a - 3; return day + (153*m + 2) / 5 + y*365 + y/4 - y/100 + y/400 - 32045; }
9. Given a date (year, month, day), Julian Day Number is sum of Days before the year Days before the month Days in the month Why not use year and month directly? y and m are shifted year and month How does it work? 2010/08 Shuo Chen (blog.csdn.net/Solstice) 9 An offset to make day 0 is Nov 24, 4714 BC return day + (153*m + 2) / 5 + y*365 + y/4 - y/100 + y/400 - 32045;
10. Shift year by two months New year starts in March ... March is month 0 in shifted year February is the last month (no. 11) of shifted year Leap day (if any) will be the last day of pervious year Length of first 11 months (m=0..10) are fixed 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31 2010/08 Shuo Chen (blog.csdn.net/Solstice) 10
11. Shifting is easy First three lines of toJulianDayNumber() month = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] After shifting, much easier to calculate Days before the year, esp. days before the month 2010/08 Shuo Chen (blog.csdn.net/Solstice) 11 int a = (14 - month) / 12; // = (month < 3) ? 1 : 0 int y = year + 4800 – a; int m = month + 12 * a – 3;
12. Days before the year The (shifted) year part of our magic formula The last three terms of the expression add in a day for each year that is a leap year. Recall that the leap day counts in pervious year The first term adds a day every 4 years The second subtracts a day back out every 100 years The third adds a day back in every 400 years To verify, calc how many leap years between 1~100 (24), 1~200 (48), 1~300 (72), 1~400 (97) 2010/08 Shuo Chen (blog.csdn.net/Solstice) 12 y*365 + y/4 - y/100 + y/400
13. Days before the month The most magical part in the formula is about m It gives cumulative sum of days in month daysBeforeMonth(March) = 0 March is the first month daysBeforeMonth(April) = 31 March has 31 days daysBeforeMonth(May) = 61 plus April’s 30 days daysBeforeMonth(Feb) = 337 total days of March to Jan 2010/08 Shuo Chen (blog.csdn.net/Solstice) 13 daysBeforeMonth(m) := (153*m + 2) / 5
14. Days before the month, cont’d By shifting 2-month, first 11 months have fixed length, so it’s much easier to calc cumulative sum No matter the last month (Feb) has 28 or 29 days, it will be addressed in the days in the month part It can be done either with look-up table, built with std::partial_sum(), or a simple function We will see how the coefficients come from Algorithm 199, Comm. of the ACM, Aug 1963 2010/08 Shuo Chen (blog.csdn.net/Solstice) 14
16. Function for days before month Find a function f(m), so that That is, find a line drills through each pair of dots 2010/08 Shuo Chen (blog.csdn.net/Solstice) 16
17. Find a straight line that fits Since the number of days of first 11 months are either 30 or 31, we try a straight line first, that is, a linear function y=ax+b To find out a and b, we finda line which is close to themiddle points of every pairs That is, find a line that fits xi = {0, 1, 2, 3, …, 11} yi = {0.5, 31.5, 61.5, 92.5, …, 337.5} 2010/08 Shuo Chen (blog.csdn.net/Solstice) 17
18. Simple linear regression The estimation of a and b are http://en.wikipedia.org/wiki/Simple_linear_regression Result a = 30.601, b = 0.52564 (regress.m in code) To get integer coefficients, we could round a and b a = 30.6 and b = 0.5 ⇒ (306*x+5)/10 a = 30.6 and b = 0.4 ⇒ (153*x+2)/5 Both happen to give correct answers, we’re done. 2010/08 Shuo Chen (blog.csdn.net/Solstice) 18
19. Break down Julian Day Number Inverse function of toJulianDayNumber() Could it possibly be correct? 2010/08 Shuo Chen (blog.csdn.net/Solstice) 19 YearMonthDaytoYearMonthDay(intjulianDayNumber) { int a = julianDayNumber + 32044; int b = (4*a + 3) / 146097; int c = a - ((b * 146097) / 4); int d = (4*c + 3) / 1461; int e = c - ((1461 * d) / 4); int m = (5*e + 2) / 153; YearMonthDayymd; ymd.day = e - ((153*m + 2) / 5) + 1; ymd.month = m + 3 - 12 * (m / 10); ymd.year = b*100 + d - 4800 + m/10; return ymd; } structYearMonthDay { int year; int month; // [1..12] int day; };
20. Two nested cycles of calendar A cycle consists four phases, first three phases are in the same length, last phase has one more day Outter cycle, 4 centuries, 146097 days Phase 0, year 1~100, 24 leap years, 36524 days Phase 1 and 2, same length (one century) Phase 3, year 301~400, 25 leap years, 36525 days Inner cycle, 4 years, 1461 days Phase 0, 1st year, 365 days Phase 1 and 2, same length (one year) Phase 3, 4th year, leap year, 366 days 2010/08 Shuo Chen (blog.csdn.net/Solstice) 20
22. Determine phases in cycles Formulas to break a day x into phases and offsets n is length of phase (365 or 36524), 4n+1 is cycle len. p is phase, 0~3 for cycle 1, 4~7 for cycle 2, and so on b is start day of phase p d is offset of x in phase p Eg. Day 2000 is Phase 5 of inner cycle 174th day of that year 2010/08 Shuo Chen (blog.csdn.net/Solstice) 22
23. Put them together Review the code of toYearMonthDay() Are you convinced? 2010/08 Shuo Chen (blog.csdn.net/Solstice) 23 int a = julianDayNumber + 32044; // 0-th day is Mar 1, epoch year int b = (4*a + 3) / 146097; // century (phase of outer cycle) int c = a - ((b * 146097) / 4); // days in the century int d = (4*c + 3) / 1461; // year in the century (inner phase) int e = c - ((1461 * d) / 4); // days in the year int m = (5*e + 2) / 153; // shifted month in the year YearMonthDayymd; ymd.day = e - ((153*m + 2) / 5) + 1; // day of the month ymd.month = m + 3 - 12 * (m / 10); // normal month ymd.year = b*100 + d - 4800 + m/10; // normal year
24. Final note Last inner cycle may be incomplete, but doesn’t matter. Eg. 2100 is not leap year Inner cycle 2096-03-01~2100-02-28 has 1460 days 2100-03-01 belongs to next (inner and outer) cycle Moving leap day to the end of year, simplified a lot The ancient Roman calendar started its year on 1st March Integer arithmetic can be tricky and useful 2010/08 Shuo Chen (blog.csdn.net/Solstice) 24
25. What do we have A function maps dates in Gregorian calendar to consecutive positive integers (known as Julian Day Number) An inverse function breaks down Julian Day Number to year, month and day Be convinced those mappings work (I hope so.) Let’s put it into real program, design a Date class 2010/08 Shuo Chen (blog.csdn.net/Solstice) 25
26. Design a Date class For civil or business usage Not for historian (dates before 1900) Not for rocket science or astronomy Assuming the current Gregorian calendar always was, and always will be, in effect. See the history of adoption of Gregorian calendar at the end of this slides 2010/08 Shuo Chen (blog.csdn.net/Solstice) 26
27. Define data member(s) The text book way The professional way 2010/08 Shuo Chen (blog.csdn.net/Solstice) 27 class Date { // ... private: int year_; int month_; int day_; }; class Date { // ... private: intjulianDayNumber_; }; Full code: http://github.com/chenshuo/recipes/tree/master/datetime/
28. Define member functions Date() Date(int y, int m, int d) explicit Date(intjdn) explicit Date(const struct tm&) // default copy-ctor and assignment bool valid() const int year() const int month() const int day() const intweekDay() const structYearMonthDayyeaMonthDay() const string toIsoString() const 2010/08 Shuo Chen (blog.csdn.net/Solstice) 28
29. Design decisions Make it a value type, and make it immutable Doesn’t provide today() The date should be injected to the system, not simply taken from local time or GMT time. Make testing simple. You don’t have to wait for years to get a date like 2012-02-29 for testing Month ranges in [1, 12] Let printf(“%4d-%02d-%02d”, date.year(), date.month(), date.day()) prints intuitive result Same as other date libraries except C’s struct tm 2010/08 Shuo Chen (blog.csdn.net/Solstice) 29
30. Unit Tests Inspired by The Elements of Programming Style 2/e, p.54 2010/08 Shuo Chen (blog.csdn.net/Solstice) 30 intjulianDayNumber = 2415021; // 1900-01-01 intweekDay = 1; // Monday int days[2][12+1] = { { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }}; for (int year = 1900; year < 2500; ++year) { for (int month = 1; month <= 12; ++month) { for (int day = 1; day <= days[isLeap(year)][month]; ++day) { // check Date d(year, month, day) and d2(julianDayNumber) ++julianDayNumber; weekDay= (weekDay+1) % 7; } } }
31. Alternative designs Strong type Year, Month and Day The Most Important Design Guideline?, by Scott Meyers, IEEE Software, July/August 2004. Move toIsoString() outside of class How Non-Member Functions Improve Encapsulation, by Scott Meyers, CUJ February 2000. Item 18 and 23 of Effective C++ 3rd ed. Provides more features parseIsoString() // yyyy-mm-dd getNextMonday(), etc. 2010/08 Shuo Chen (blog.csdn.net/Solstice) 31
32. Available libraries Boost::date_time Use it if you need “customization and extension” Python datetime http://docs.python.org/library/datetime.html Ruby date http://ruby-doc.org/stdlib/libdoc/date/rdoc/ Java Joda Time http://joda-time.sourceforge.net/ 2010/08 Shuo Chen (blog.csdn.net/Solstice) 32
33. POSIX.1 2003 Doesn’t provide date function Date time calc based on Unix time, ie. Seconds since 1970-01-01 00:00:00 UTC Exposed to year 2038 problem on 32-bit platform http://code.google.com/p/y2038/ Will talk more in coming parts, when we talk UTC time and local time 2010/08 Shuo Chen (blog.csdn.net/Solstice) 33
34. A bit of history Calendars are notoriously idiosyncratic. http://en.wikipedia.org/wiki/Gregorian_calendar#History Gregorian calendar begins in 1582. Not all countries adopted at same time England, United States (ex. Alaska), 1752 $ cal Sep 1752 # try it on Linux 1700 was a leap year in England history Russia, 1918 October Revolution happened on 1917-11-07 Gregorian 1900 was a leap year in Russia history 2010/08 Shuo Chen (blog.csdn.net/Solstice) 34
35. To be continued Time keeping in programs Always record happened event in UTC time Time zones and daylight saving time Consider keep scheduled event in local time Do not hardcode time zone offset or DST rules Time in a distributed system Two timestamps from two hosts are not comparable, unless you know the clock skew of those two hosts NTP isn’t good enough for monitoring latency in LAN 2010/08 Shuo Chen (blog.csdn.net/Solstice) 35