begin process at 2010 09 03 03:11:01
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Date / Heure

 > CLASSE MOMENT V2.0

CLASSE MOMENT V2.0


 Information sur la source

Note :
Aucune note
Catégorie :Date / Heure Classé sous :date, heure, moment, pattern, epoch Niveau :Débutant Date de création :17/02/2009 Date de mise à jour :17/02/2009 16:20:36 Vu / téléchargé :1 375 / 48

Auteur : le_duche

Ecrire un message privé
Commentaire sur cette source (5)
Ajouter un commentaire et/ou une note

 Description

ABSTRACT:

Lors de divers programmes de tous types, il est extrêmement courant d'avoir recours à une ligne du temps: pour retenir l'heure d'un événement, afficher l'heure courante du système, connaître le jour de la semaine d'une date particulière, connaître l'heure sur un autre fuseau horaire, et faire diverses opérations sur ces moments. C'est dans cette optique que j'ai décidé de développer la classe Moment, utile pour de très nombreuses applications. J'ai également accordé beaucoup d'importance à l'affichage des instances sous diverses formes au moyen d'une notion de pattern.

Il s'agit ici de la version 2.0, la version 1.0 est une vieille version officiellement non disponible, mais elle fait partie de mes autres sources sur ce site. De nombreuses améliorations sont encore à envisager (toute bonne idée est évidemment la bienvenue).

Le fonctionnement général de cette classe est basé sur le nombre de millisecondes écoulées depuis le premier janvier 1600 à 0h00'00"000. Une conversion dans des variables intuitives (année, mois, jour, jour de la semaine, heure, minute, seconde et milliseconde) est générée à chaque modification de cette variable, en tenant compte du fuseau horaire et du passage aux heures d'été.

J'ai choisi de limiter la remontée dans le temps à l'an 1600 pour une raison très simple: Le calendrier que nous utilisons, qui a débuté au XVème siècle, est basé sur des cycles de 400 ans. En effet, une année est bissextile si elle est un multiple de 4, exception faite des années multiples de 100, cette exception étant levée pour les années multiples de 400. L'an 1600 est la première année débutant un cycle de 400 ans qui suit l'établissement du calendrier actuel. Il serait erroné de regarder les années précédentes avec le calendrier actuel, et il serait pénible d'implémenter un autre calendrier pour ces années là (du moins dans cette version-ci).

Source

  • /*
  • * moment.h -- Project Moment v2.0
  • *
  • * Created by Christophe Dumeunier on 09/02/09.
  • * Copyright 2009 Christophe Dumeunier. All rights reserved.
  • * This file is free; you can redistribute it and/or modify
  • * it under the terms of the GNU General Public License as published by
  • * the Free Software Foundation; either version 2 of the License, or
  • * (at your option) any later version.
  • *
  • * Créé par Christophe Dumeunier le 09/02/09.
  • * Copyright 2009 Christophe Dumeunier. Tous droits réservés.
  • * Ce fichier est gratuit; vous pouvez le redistribuer et/ou le modifier
  • * selon les termes de la licence générale publique GNU publiée par
  • * la Free Software Fondation; à partir de la version 2 de cette licence.
  • *
  • * Contact: christophe.dumeunier@gmail.com
  • *
  • */
  • #ifndef _MOMENT_H
  • #define _MOMENT_H
  • #include <iostream>
  • using namespace std;
  • #define JANUARY 1
  • #define FEBRUARY 2
  • #define MARCH 3
  • #define APRIL 4
  • #define MAY 5
  • #define JUNY 6
  • #define JULY 7
  • #define AUGUST 8
  • #define SEPTEMBER 9
  • #define OCTOBER 10
  • #define NOVEMBER 11
  • #define DECEMBER 12
  • #define SUNDAY 0
  • #define MONDAY 1
  • #define TUESDAY 2
  • #define WEDNESDAY 3
  • #define THURSDAY 4
  • #define FRIDAY 5
  • #define SATERDAY 6
  • #define MIN_DAY_OF_WEEK SUNDAY
  • #define MAX_DAY_OF_WEEK SATERDAY
  • #define LANG_ENGLISH 0
  • #define LANG_FRENCH 1
  • #define LANG_DUTCH 2
  • #define LANG_GERMAN 3
  • #define LANG_ITALIAN 4
  • #define LANG_SPANISH 5
  • #define NBR_LANG 6
  • #define UNIT_MILLISECOND 1
  • #define UNIT_SECOND 2
  • #define UNIT_MINUTE 3
  • #define UNIT_HOUR 4
  • #define UNIT_DAY 5
  • #define UNIT_WEEK 6 // 7 jours
  • #define UNIT_SHORT_MONTH 7 // 28 jours
  • #define UNIT_SPECIAL_MONTH 8 // 29 jours
  • #define UNIT_NORMAL_MONTH 9 // 30 jours
  • #define UNIT_LONG_MONTH 10 // 31 jours
  • #define UNIT_MEAN_MONTH 11 // 30.436875 jours
  • #define UNIT_NORMAL_YEAR 12 // 365 jours
  • #define UNIT_LONG_YEAR 13 // 366 jours
  • #define UNIT_MEAN_YEAR 14 // 365.2425 jours
  • #define MIN_UNIT UNIT_MILLISECOND
  • #define MAX_UNIT UNIT_MEAN_YEAR
  • #define TIME_ZONE_MIDWAY -660
  • #define TIME_ZONE_HAWAII -600
  • #define TIME_ZONE_ALASKA -540
  • #define TIME_ZONE_TIJUANA -480
  • #define TIME_ZONE_ARIZONA -420
  • #define TIME_ZONE_MEXICO -360
  • #define TIME_ZONE_BOGOTA -300
  • #define TIME_ZONE_CARACAS -270
  • #define TIME_ZONE_SANTIAGO -240
  • #define TIME_ZONE_TERRE_NEUVE -210
  • #define TIME_ZONE_BRASILIA -180
  • #define TIME_ZONE_ATLANTIQUE -120
  • #define TIME_ZONE_CAP_VERT -60
  • #define TIME_ZONE_LONDRES 0
  • #define TIME_ZONE_PARIS 60
  • #define TIME_ZONE_BUCAREST 120
  • #define TIME_ZONE_MOSCOU 180
  • #define TIME_ZONE_TEHERAN 210
  • #define TIME_ZONE_BAKU 240
  • #define TIME_ZONE_KABOUL 270
  • #define TIME_ZONE_ISLAMABAD 300
  • #define TIME_ZONE_CALCUTTA 330
  • #define TIME_ZONE_KATMANDOU 345
  • #define TIME_ZONE_ASTANA 360
  • #define TIME_ZONE_RANGOON 390
  • #define TIME_ZONE_HANOI 420
  • #define TIME_ZONE_PEKIN 480
  • #define TIME_ZONE_TOKYO 540
  • #define TIME_ZONE_DARWIN 570
  • #define TIME_ZONE_SYDNEY 600
  • #define TIME_ZONE_NOUVELLE_CALEDONIE 660
  • #define TIME_ZONE_WELLINGTON 720
  • #define TIME_ZONE_NUKUALOFA 780
  • #define MIN_TIME_ZONE TIME_ZONE_MIDWAY
  • #define MAX_TIME_ZONE TIME_ZONE_NUKUALOFA
  • #define MIN_MILLISECOND 0
  • #define MAX_MILLISECOND 999
  • #define MIN_SECOND 0
  • #define MAX_SECOND 59
  • #define MIN_MINUTE 0
  • #define MAX_MINUTE 59
  • #define MIN_HOUR 0
  • #define MAX_HOUR 23
  • #define MIN_DAY 1
  • #define MAX_DAY 31
  • #define MIN_MONTH JANUARY
  • #define MAX_MONTH DECEMBER
  • #define MIN_YEAR 1600
  • #define MAX_YEAR 59999
  • #define LEAP_CYCLE 4
  • #define LEAP_EXCEPTION_CYCLE 100
  • #define LEAP_EXCEPTION2_CYCLE 400
  • #define NBR_MILLISECONDS_IN_SECOND 1000
  • #define NBR_MILLISECONDS_IN_MINUTE 60000
  • #define NBR_MILLISECONDS_IN_HOUR 3600000
  • #define NBR_MILLISECONDS_IN_DAY 86400000
  • #define NBR_MILLISECONDS_IN_WEEK 604800000
  • #define NBR_SECONDS_IN_MINUTE 60
  • #define NBR_SECONDS_IN_HOUR 3600
  • #define NBR_SECONDS_IN_DAY 86400
  • #define NBR_SECONDS_IN_WEEK 604800
  • #define NBR_SECONDS_IN_NORMAL_YEAR 31536000
  • #define NBR_SECONDS_IN_LONG_YEAR 31622400
  • #define NBR_SECONDS_IN_NORMAL_CYCLE_4_YEARS 126230400
  • #define NBR_SECONDS_IN_SHORT_CYCLE_4_YEARS 126144000
  • #define NBR_MINUTES_IN_HOUR 60
  • #define NBR_DAYS_IN_WEEK 7
  • #define NBR_DAYS_LONG_MONTH 31
  • #define NBR_DAYS_NORMAL_MONTH 30
  • #define NBR_DAYS_SHORT_MONTH 28
  • #define NBR_DAYS_MEAN_MONTH 30.436875
  • #define NBR_DAYS_SPECIAL_MONTH 29
  • #define NBR_DAYS_IN_NORMAL_YEAR 365
  • #define NBR_DAYS_IN_LONG_YEAR 366
  • #define NBR_DAYS_IN_MEAN_YEAR 365.2425
  • #define NBR_DAYS_IN_NORMAL_CYCLE_4_YEARS 1461
  • #define NBR_DAYS_IN_SHORT_CYCLE_4_YEARS 1460
  • #define NBR_DAYS_IN_NORMAL_CYCLE_100_YEARS 36524
  • #define NBR_DAYS_IN_LONG_CYCLE_100_YEARS 36525
  • #define NBR_DAYS_IN_CYCLE_400_YEARS 146097
  • #define NBR_DAYS_TO_EPOCH 135140
  • #define DEFAULT_UNIT UNIT_SECOND
  • #define DEFAULT_LANG LANG_ENGLISH
  • #define DEFAULT_TIME_ZONE TIME_ZONE_LONDRES
  • #define DEFAULT_SUMMER_TIME_ACTIVE false
  • #define DEFAULT_PATTERN "#DD-#MN-#YYYY #HH:#MM:#SS"
  • #define DEFAULT_ORIGIN_TIME 0
  • #define DEFAULT_ORIGIN_MILLISECOND 0
  • class Moment;
  • class MomentPattern;
  • class MagicOstreamPattern;
  • //----------
  • //----------
  • class MomentPattern
  • {
  • private:
  • string pattern;
  • unsigned short lang;
  • public:
  • MomentPattern(const string&,unsigned short);
  • bool operator==(const MomentPattern&);
  • string getPattern() const;
  • unsigned short getLanguage() const;
  • void printMoment(ostream&,const Moment&) const;
  • MagicOstreamPattern operator,(ostream&) const;
  • };
  • //----------
  • //----------
  • class MagicOstreamPattern
  • {
  • private:
  • ostream* ptr_flux;
  • MomentPattern pat;
  • public:
  • MagicOstreamPattern(ostream*,MomentPattern);
  • ~MagicOstreamPattern();
  • MagicOstreamPattern operator<<(const Moment&);
  • template<class T> MagicOstreamPattern operator<<(const T& t) { *ptr_flux << t; return *this; }
  • };
  • //----------
  • //----------
  • class Moment
  • {
  • private:
  • unsigned long long total_milliseconds;
  • unsigned short year;
  • unsigned short month;
  • unsigned short day_of_month;
  • unsigned short day_of_week;
  • unsigned short hour;
  • unsigned short minute;
  • unsigned short second;
  • unsigned short millisecond;
  • short time_zone;
  • static unsigned short unit;
  • static short default_time_zone;
  • static bool summer_time_is_active;
  • static MomentPattern pattern;
  • static unsigned long long origin_time;
  • public:
  • Moment();
  • Moment(unsigned long long);
  • Moment(unsigned short,unsigned short,unsigned short,unsigned short,unsigned short,unsigned short,unsigned short);
  • Moment(const Moment&);
  • Moment& operator=(const Moment&);
  • ~Moment();
  • static unsigned short getUnit();
  • static bool setUnit(unsigned short);
  • static short getDefaultTimeZone();
  • static bool setDefaultTimeZone(short);
  • static bool summerTimeIsActive();
  • static void setSummerTimeActive();
  • static void setSummerTimeUnactive();
  • static MomentPattern getPattern();
  • static void printPattern(ostream&);
  • static void setPattern(const MomentPattern&);
  • static Moment getOrigin();
  • static void setOrigin(const Moment&);
  • short getTimeZone() const;
  • bool setTimeZone(short);
  • bool setTimeZoneWithoutAlterTime(short);
  • unsigned long long getTotalMilliseconds() const;
  • unsigned short getYear() const;
  • unsigned short getMonth() const;
  • unsigned short getDayOfMonth() const;
  • unsigned short getDayOfWeek() const;
  • unsigned short getHour() const;
  • unsigned short getMinute() const;
  • unsigned short getSecond() const;
  • unsigned short getMillisecond() const;
  • bool setTotalMilliseconds(unsigned long long);
  • bool setYear(unsigned short);
  • bool setMonth(unsigned short);
  • bool setDayOfMonth(unsigned short);
  • bool setDate(unsigned short,unsigned short,unsigned short);
  • bool setHour(unsigned short);
  • bool setMinute(unsigned short);
  • bool setSecond(unsigned short);
  • bool setMillisecond(unsigned short);
  • bool setTime(unsigned short,unsigned short,unsigned short,unsigned short);
  • bool setValues(unsigned short,unsigned short,unsigned short,unsigned short,unsigned short,unsigned short,unsigned short);
  • bool operator==(const Moment&) const;
  • bool operator!=(const Moment&) const;
  • bool operator<(const Moment&) const;
  • bool operator>(const Moment&) const;
  • bool operator<=(const Moment&) const;
  • bool operator>=(const Moment&) const;
  • double operator-(const Moment&) const;
  • Moment operator+(double) const;
  • Moment operator-(double) const;
  • void operator+=(double);
  • void operator-=(double);
  • Moment operator++();
  • Moment operator++(int);
  • Moment operator--();
  • Moment operator--(int);
  • bool jumpToFollowingDayOfWeek(unsigned short);
  • bool jumpToPreviousDayOfWeek(unsigned short);
  • Moment operator+() const;
  • Moment operator-() const;
  • Moment operator*(double) const;
  • Moment operator/(double) const;
  • void operator*=(double);
  • void operator/=(double);
  • void update();
  • private:
  • void convertToMilliseconds();
  • void convertFromMilliseconds();
  • };
  • ostream& operator<<(ostream&,const Moment&);
  • #endif
/*
 *  moment.h -- Project Moment v2.0
 *
 *  Created by Christophe Dumeunier on 09/02/09.
 *  Copyright 2009 Christophe Dumeunier. All rights reserved.
 *  This file is free; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *  
 *  Créé par Christophe Dumeunier le 09/02/09.
 *  Copyright 2009 Christophe Dumeunier. Tous droits réservés.
 *  Ce fichier est gratuit; vous pouvez le redistribuer et/ou le modifier
 *  selon les termes de la licence générale publique GNU publiée par
 *  la Free Software Fondation; à partir de la version 2 de cette licence.
 *  
 *  Contact: christophe.dumeunier@gmail.com
 *
 */

#ifndef _MOMENT_H
#define _MOMENT_H

#include <iostream>
using namespace std;

#define JANUARY 1
#define FEBRUARY 2
#define MARCH 3
#define APRIL 4
#define MAY 5
#define JUNY 6
#define JULY 7
#define AUGUST 8
#define SEPTEMBER 9
#define OCTOBER 10
#define NOVEMBER 11
#define DECEMBER 12

#define SUNDAY 0
#define MONDAY 1
#define TUESDAY 2
#define WEDNESDAY 3
#define THURSDAY 4
#define FRIDAY 5
#define SATERDAY 6
#define MIN_DAY_OF_WEEK SUNDAY
#define MAX_DAY_OF_WEEK SATERDAY

#define LANG_ENGLISH 0
#define LANG_FRENCH 1
#define LANG_DUTCH 2
#define LANG_GERMAN 3
#define LANG_ITALIAN 4
#define LANG_SPANISH 5
#define NBR_LANG 6

#define UNIT_MILLISECOND 1
#define UNIT_SECOND 2
#define UNIT_MINUTE 3
#define UNIT_HOUR 4
#define UNIT_DAY 5
#define UNIT_WEEK 6  // 7 jours
#define UNIT_SHORT_MONTH 7  // 28 jours
#define UNIT_SPECIAL_MONTH 8  // 29 jours
#define UNIT_NORMAL_MONTH 9  // 30 jours
#define UNIT_LONG_MONTH 10  // 31 jours
#define UNIT_MEAN_MONTH 11  // 30.436875 jours
#define UNIT_NORMAL_YEAR 12  // 365 jours
#define UNIT_LONG_YEAR 13  // 366 jours
#define UNIT_MEAN_YEAR 14  // 365.2425 jours
#define MIN_UNIT UNIT_MILLISECOND
#define MAX_UNIT UNIT_MEAN_YEAR

#define TIME_ZONE_MIDWAY -660
#define TIME_ZONE_HAWAII -600
#define TIME_ZONE_ALASKA -540
#define TIME_ZONE_TIJUANA -480
#define TIME_ZONE_ARIZONA -420
#define TIME_ZONE_MEXICO -360
#define TIME_ZONE_BOGOTA -300
#define TIME_ZONE_CARACAS -270
#define TIME_ZONE_SANTIAGO -240
#define TIME_ZONE_TERRE_NEUVE -210
#define TIME_ZONE_BRASILIA -180
#define TIME_ZONE_ATLANTIQUE -120
#define TIME_ZONE_CAP_VERT -60
#define TIME_ZONE_LONDRES 0
#define TIME_ZONE_PARIS 60
#define TIME_ZONE_BUCAREST 120
#define TIME_ZONE_MOSCOU 180
#define TIME_ZONE_TEHERAN 210
#define TIME_ZONE_BAKU 240
#define TIME_ZONE_KABOUL 270
#define TIME_ZONE_ISLAMABAD 300
#define TIME_ZONE_CALCUTTA 330
#define TIME_ZONE_KATMANDOU 345
#define TIME_ZONE_ASTANA 360
#define TIME_ZONE_RANGOON 390
#define TIME_ZONE_HANOI 420
#define TIME_ZONE_PEKIN 480
#define TIME_ZONE_TOKYO 540
#define TIME_ZONE_DARWIN 570
#define TIME_ZONE_SYDNEY 600
#define TIME_ZONE_NOUVELLE_CALEDONIE 660
#define TIME_ZONE_WELLINGTON 720
#define TIME_ZONE_NUKUALOFA 780
#define MIN_TIME_ZONE TIME_ZONE_MIDWAY
#define MAX_TIME_ZONE TIME_ZONE_NUKUALOFA

#define MIN_MILLISECOND 0
#define MAX_MILLISECOND 999
#define MIN_SECOND 0
#define MAX_SECOND 59
#define MIN_MINUTE 0
#define MAX_MINUTE 59
#define MIN_HOUR 0
#define MAX_HOUR 23
#define MIN_DAY 1
#define MAX_DAY 31
#define MIN_MONTH JANUARY
#define MAX_MONTH DECEMBER
#define MIN_YEAR 1600
#define MAX_YEAR 59999

#define LEAP_CYCLE 4
#define LEAP_EXCEPTION_CYCLE 100
#define LEAP_EXCEPTION2_CYCLE 400

#define NBR_MILLISECONDS_IN_SECOND 1000
#define NBR_MILLISECONDS_IN_MINUTE 60000
#define NBR_MILLISECONDS_IN_HOUR 3600000
#define NBR_MILLISECONDS_IN_DAY 86400000
#define NBR_MILLISECONDS_IN_WEEK 604800000
#define NBR_SECONDS_IN_MINUTE 60
#define NBR_SECONDS_IN_HOUR 3600
#define NBR_SECONDS_IN_DAY 86400
#define NBR_SECONDS_IN_WEEK 604800
#define NBR_SECONDS_IN_NORMAL_YEAR 31536000
#define NBR_SECONDS_IN_LONG_YEAR 31622400
#define NBR_SECONDS_IN_NORMAL_CYCLE_4_YEARS 126230400
#define NBR_SECONDS_IN_SHORT_CYCLE_4_YEARS 126144000
#define NBR_MINUTES_IN_HOUR 60
#define NBR_DAYS_IN_WEEK 7
#define NBR_DAYS_LONG_MONTH 31
#define NBR_DAYS_NORMAL_MONTH 30
#define NBR_DAYS_SHORT_MONTH 28
#define NBR_DAYS_MEAN_MONTH 30.436875
#define NBR_DAYS_SPECIAL_MONTH 29
#define NBR_DAYS_IN_NORMAL_YEAR 365
#define NBR_DAYS_IN_LONG_YEAR 366
#define NBR_DAYS_IN_MEAN_YEAR 365.2425
#define NBR_DAYS_IN_NORMAL_CYCLE_4_YEARS 1461
#define NBR_DAYS_IN_SHORT_CYCLE_4_YEARS 1460
#define NBR_DAYS_IN_NORMAL_CYCLE_100_YEARS 36524
#define NBR_DAYS_IN_LONG_CYCLE_100_YEARS 36525
#define NBR_DAYS_IN_CYCLE_400_YEARS 146097
#define NBR_DAYS_TO_EPOCH 135140

#define DEFAULT_UNIT UNIT_SECOND
#define DEFAULT_LANG LANG_ENGLISH
#define DEFAULT_TIME_ZONE TIME_ZONE_LONDRES
#define DEFAULT_SUMMER_TIME_ACTIVE false
#define DEFAULT_PATTERN "#DD-#MN-#YYYY #HH:#MM:#SS"
#define DEFAULT_ORIGIN_TIME 0
#define DEFAULT_ORIGIN_MILLISECOND 0

class Moment;
class MomentPattern;
class MagicOstreamPattern;

//----------
//----------

class MomentPattern
{
	private:
	
		string pattern;
		unsigned short lang;
	
	public:
	
		MomentPattern(const string&,unsigned short);
		bool operator==(const MomentPattern&);
		
		string getPattern() const;
		unsigned short getLanguage() const;
		void printMoment(ostream&,const Moment&) const;
		MagicOstreamPattern operator,(ostream&) const;
	
};

//----------
//----------

class MagicOstreamPattern
{
	private:
	
		ostream* ptr_flux;
		MomentPattern pat;
	
	public:
	
		MagicOstreamPattern(ostream*,MomentPattern);
		~MagicOstreamPattern();
		
		MagicOstreamPattern operator<<(const Moment&);
		template<class T> MagicOstreamPattern operator<<(const T& t) { *ptr_flux << t; return *this; }
	
};

//----------
//----------

class Moment
{
	private:
	
		unsigned long long total_milliseconds;
		unsigned short year;
		unsigned short month;
		unsigned short day_of_month;
		unsigned short day_of_week;
		unsigned short hour;
		unsigned short minute;
		unsigned short second;
		unsigned short millisecond;
		short time_zone;
		
		static unsigned short unit;
		static short default_time_zone;
		static bool summer_time_is_active;
		static MomentPattern pattern;
		static unsigned long long origin_time;
	
	public:
	
		Moment();
		Moment(unsigned long long);
		Moment(unsigned short,unsigned short,unsigned short,unsigned short,unsigned short,unsigned short,unsigned short);
		Moment(const Moment&);
		Moment& operator=(const Moment&);
		~Moment();
		
		static unsigned short getUnit();
		static bool setUnit(unsigned short);
		static short getDefaultTimeZone();
		static bool setDefaultTimeZone(short);
		static bool summerTimeIsActive();
		static void setSummerTimeActive();
		static void setSummerTimeUnactive();
		static MomentPattern getPattern();
		static void printPattern(ostream&);
		static void setPattern(const MomentPattern&);
		static Moment getOrigin();
		static void setOrigin(const Moment&);
		
		short getTimeZone() const;
		bool setTimeZone(short);
		bool setTimeZoneWithoutAlterTime(short);
		
		unsigned long long getTotalMilliseconds() const;
		unsigned short getYear() const;
		unsigned short getMonth() const;
		unsigned short getDayOfMonth() const;
		unsigned short getDayOfWeek() const;
		unsigned short getHour() const;
		unsigned short getMinute() const;
		unsigned short getSecond() const;
		unsigned short getMillisecond() const;
		bool setTotalMilliseconds(unsigned long long);
		bool setYear(unsigned short);
		bool setMonth(unsigned short);
		bool setDayOfMonth(unsigned short);
		bool setDate(unsigned short,unsigned short,unsigned short);
		bool setHour(unsigned short);
		bool setMinute(unsigned short);
		bool setSecond(unsigned short);
		bool setMillisecond(unsigned short);
		bool setTime(unsigned short,unsigned short,unsigned short,unsigned short);
		bool setValues(unsigned short,unsigned short,unsigned short,unsigned short,unsigned short,unsigned short,unsigned short);
		
		bool operator==(const Moment&) const;
		bool operator!=(const Moment&) const;
		bool operator<(const Moment&) const;
		bool operator>(const Moment&) const;
		bool operator<=(const Moment&) const;
		bool operator>=(const Moment&) const;
		
		double operator-(const Moment&) const;
		Moment operator+(double) const;
		Moment operator-(double) const;
		void operator+=(double);
		void operator-=(double);
		Moment operator++();
		Moment operator++(int);
		Moment operator--();
		Moment operator--(int);
		
		bool jumpToFollowingDayOfWeek(unsigned short);
		bool jumpToPreviousDayOfWeek(unsigned short);
		Moment operator+() const;
		Moment operator-() const;
		Moment operator*(double) const;
		Moment operator/(double) const;
		void operator*=(double);
		void operator/=(double);
		
		void update();
	
	private:
	
		void convertToMilliseconds();
		void convertFromMilliseconds();
	
};

ostream& operator<<(ostream&,const Moment&);

#endif


 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Historique

17 février 2009 15:56:58 :
Edition du texte de présentation.
17 février 2009 16:20:36 :
Zip sans les fichiers Mac OS X

 Sources du même auteur

Source avec Zip GÉNÉRATEUR DE UNIT TEST
Source avec Zip GESTION DE LA DATE DE L'HEURE ET DU TEMPS
Source avec Zip EXEMPLE SDL : FAIRE COURIR ET FREINER SONIC
Source avec Zip QUELQUES FONCTIONS POUR FACILITER LA PRISE EN MAIN DE LA SDL
Source avec Zip RÉSOLUTION ET CRÉATIONS DE SUDOKUS

 Sources de la même categorie

Source avec Zip CLASSE DE DATE LOCALISÉE (20 LANGUES) par exar
CALCUL DATE DE PAQUES (DATE MOBILE) par steph12358
Source avec une capture VACCATION (AVEC FONCTION) CONSOLERIE, REMIX GCC par sebman
Source avec Zip Source avec une capture AFFICHER ET DIRE L'HEURE (REPONSE FORUM) par ndubien
Source avec Zip Source avec une capture ARRÊT AUTOMATIQUE DE WINDOWS. par patarotalexandre

 Sources en rapport avec celle ci

Source avec Zip CLASSE DE DATE LOCALISÉE (20 LANGUES) par exar
Source avec une capture ALGORITHME DE MAURICE KRAITCHIK (1882&#65533;1957) par thebroyeur
Source avec Zip Source avec une capture CALENDRIER (WIN64) par BruNews
Source avec Zip CHANGEUR DATE FICHIER (WIN32) par BruNews
Source avec Zip GESTION DE LA DATE DE L'HEURE ET DU TEMPS par le_duche

Commentaires et avis

Commentaire de le_duche le 17/02/2009 16:21:57

Amusez-vous bien !
Vous trouverez toute la documentation sur cette source dans le pdf qui accompagne.

Commentaire de exar le 18/02/2009 11:04:52

Hello !

J'ai survolé le code ainsi que la doc.  La doc est claire et compréhensible.  Le code est propre, semble efficace (je n'ai pas testé).  Manquent juste quelques commentaires.
Sinon, vraiment bien !

Bonne prog !

Commentaire de le_duche le 25/02/2009 14:58:38

J'essaye de faire du code qui se passe de commentaires par l'utilisation de noms de variables appropriés, de macro à la place de constantes sans signification, etc...
Si certains points ne sont pas clairs, c'est toujours bien de le mentionner, je ne compte les comenter, mais bien améliorer ma façon de coder pour de telles séquences.

Pour ce qui est de la justification d'un algorithme, je pense que ça ne doit pas se trouver dans le code, mais bien éventuellement en annexe.

Commentaire de exar le 25/02/2009 15:18:18

Je n'avais pas d'idée précise quant aux commentaires, je n'avais que survolé rapidement le code.
Je n'avais pas non plus capté le MomentPattern: bien foutu !  Juste une petite chose cependant: pourquoi ne pas stocker les noms en différentes langues dans un tableau multidimensionnel ?  Ce serait plus simple si tu ajoutes d'autres langues, non ?

Commentaire de le_duche le 26/02/2009 16:44:36

C'est une question à laquelle j'ai pas mal réfléchis. Et il s'avère que c'est un choix entre propreté du code et qualité d'exécution.
D'un côté c'est vrai que déclarer un tableau, c'est tout propre. Cela-dit en terme de quantité de lignes de code ce n'est pas beaucoup inférieur d'y injecter les donées que mes if.
Mais avec n langues, il y a une portion (n-1)/n des déclarations qui sont faites qui sont inutiles, avec une vraie internationalisation, ça peut devenir très lourd.

Voila donc ce qui justifie ce code très lourd et très laid ^_^

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

Récupération de la date et heure de cration d'un fichier [ par MELISA ] Bonjour à tousJ'essaie de récupérer la date et heure de création d'un fichier.Existe-t-il déjà une API à intégrer?Merci beaucoup pour votre aide.MELIS transformation d'une date et heure en lettres [ par Philuch ] Philuchsalut!!J'ai besoin d'une aide urgente. Je recherche une fonction qui permettra de transformer une date et heure d'un fichier sur cd-rom [ par shinevilkyo ] bonjour,je cherche a connaitre la date et l heure de creation d'un fichier qui ce trouve sur un cd-rom et po sur un disk dur car j ai essai avec les f modif de la date et de l'heure system [ par bwoufy86 ] Voila, je cherche a faire un soft en c++ ou je peux changer la date et l'heure system.J pensée utilisé la cde system("xxx");mais je trouve po ca jolie C++ Builder Date/heure [ par brums972 ] salut, j'aimerai savoir comment calculer le tps écoulé en deux date/heure sous le format 02/03/2004 05:34 et 11/03/2004 14:58, avec quelle fonction je Comment restituer une date ou heure dans un Edit en API [ par LaPatoshe ] Encore bonjour à tous. Je cherche à récupérer la date du jour et l'heure et les restituer dans des zones d'édition.J'ai tenté l'opération en créant un langage C [ par wesslett ] je suis d&#233;butant et nouveau&nbsp; dans ce forum&nbsp;....!! Comment peut on afficher la&nbsp;date et l'&nbsp;heure lors d'une saisie de donn&#233 pb d'affichage de DATE HEURE (Dev-CPP) [ par phenX ] Pour pouvoir afficher la date dans un fichier texte, je fait: fprintf(fichier,"%d\t\t", time(&amp;H) et j'obtiens, dans le fichier: 1129296004 qui do Comparaison de date et heure [ par albertusse ] Quelqu'un aurait t-il un source qui permete de compararé deux date/heure Merci. Albertusse recuperation heure et date [ par ancat ] Bonsoir, es-ce qu'il existe une fonction permettant de recupere l'heure en win 32?MerciBye ANCAT[font=Comic Sans MS]


Nos sponsors


Sondage...

CalendriCode

Septembre 2010
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
27282930   

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 2,340 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales