DriveHQ Start Menu
Cloud Drive Mapping
Folder Sync
Cloud Backup
True Drop Box
FTP/SFTP Hosting
Group Account
DriveHQ Start Menu
Online File Server
My Storage
|
Manage Shares
|
Publishes
|
Drop Boxes
|
Group Account
WebDAV Drive Mapping
Cloud Drive Home
|
WebDAV Guide
|
Drive Mapping Tool
|
Drive Mapping URL
Complete Data Backup
Backup Guide
|
Online Backup Tool
|
Cloud-to-Cloud Backup
FTP, Email & Web Service
FTP Home
|
FTP Hosting FAQ
|
Email Hosting
|
EmailManager
|
Web Hosting
Help & Resources
About
|
Enterprise Service
|
Partnership
|
Comparisons
|
Support
Quick Links
Security and Privacy
Download Software
Service Manual
Use Cases
Group Account
Online Help
Blog
Contact
Cloud Surveillance
Sign Up
Login
Features
Business Features
Online File Server
FTP Hosting
Cloud Drive Mapping
Cloud File Backup
Email Backup & Hosting
Cloud File Sharing
Folder Synchronization
Group Management
True Drop Box
Full-text Search
AD Integration/SSO
Mobile Access
IP Camera & DVR Solution
More...
Personal Features
Personal Cloud Drive
Backup All Devices
Mobile APPs
Personal Web Hosting
Sub-Account (for Kids)
Home/PC/Kids Monitoring
More...
Software
DriveHQ Drive Mapping Tool
DriveHQ FileManager
DriveHQ Online Backup
DriveHQ Mobile Apps
Pricing
Business Plans & Pricing
Personal Plans & Pricing
Price Comparison with Others
Feature Comparison with Others
Install Mobile App
Sign up
Creating account...
Invalid character in username! Only 0-9, a-z, A-Z, _, -, . allowed.
Username is required!
Invalid email address!
E-mail is required!
Password is required!
Password is invalid!
Password and confirmation do not match.
Confirm password is required!
I accept
Membership Agreement
Please read the Membership Agreement and check "I accept"!
Free Quick Sign-up
Sign-up Page
Log in
Signing in...
Username or e-mail address is required!
Password is required!
Keep me logged in
Quick Login
Forgot Password
Up
Upload
Download
Share
Publish
New Folder
New File
Copy
Cut
Delete
Paste
Rate
Upgrade
Rotate
Effect
Edit
Slide
History
#ifndef _DATE_TIME_ADJUST_FUNCTORS_HPP___ #define _DATE_TIME_ADJUST_FUNCTORS_HPP___ /* Copyright (c) 2002,2003 CrystalClear Software, Inc. * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) * Author: Jeff Garland, Bart Garst * $Date: 2008-02-27 15:00:24 -0500 (Wed, 27 Feb 2008) $ */ #include "boost/date_time/date.hpp" #include "boost/date_time/wrapping_int.hpp" namespace boost { namespace date_time { //! Functor to iterate a fixed number of days template
class day_functor { public: typedef typename date_type::duration_type duration_type; day_functor(int f) : f_(f) {} duration_type get_offset(const date_type& d) const { // why is 'd' a parameter??? // fix compiler warnings d.year(); return duration_type(f_); } duration_type get_neg_offset(const date_type& d) const { // fix compiler warnings d.year(); return duration_type(-f_); } private: int f_; }; //! Provides calculation to find next nth month given a date /*! This adjustment function provides the logic for 'month-based' * advancement on a ymd based calendar. The policy it uses * to handle the non existant end of month days is to back * up to the last day of the month. Also, if the starting * date is the last day of a month, this functor will attempt * to adjust to the end of the month. */ template
class month_functor { public: typedef typename date_type::duration_type duration_type; typedef typename date_type::calendar_type cal_type; typedef typename cal_type::ymd_type ymd_type; typedef typename cal_type::day_type day_type; month_functor(int f) : f_(f), origDayOfMonth_(0) {} duration_type get_offset(const date_type& d) const { ymd_type ymd(d.year_month_day()); if (origDayOfMonth_ == 0) { origDayOfMonth_ = ymd.day; day_type endOfMonthDay(cal_type::end_of_month_day(ymd.year,ymd.month)); if (endOfMonthDay == ymd.day) { origDayOfMonth_ = -1; //force the value to the end of month } } typedef date_time::wrapping_int2
wrap_int2; typedef typename wrap_int2::int_type int_type; wrap_int2 wi(ymd.month); //calc the year wrap around, add() returns 0 or 1 if wrapped int_type year = wi.add(static_cast
(f_)); year = static_cast
(year + ymd.year); //calculate resulting year // std::cout << "trace wi: " << wi.as_int() << std::endl; // std::cout << "trace year: " << year << std::endl; //find the last day for the new month day_type resultingEndOfMonthDay(cal_type::end_of_month_day(year, wi.as_int())); //original was the end of month -- force to last day of month if (origDayOfMonth_ == -1) { return date_type(year, wi.as_int(), resultingEndOfMonthDay) - d; } day_type dayOfMonth = origDayOfMonth_; if (dayOfMonth > resultingEndOfMonthDay) { dayOfMonth = resultingEndOfMonthDay; } return date_type(year, wi.as_int(), dayOfMonth) - d; } //! Returns a negative duration_type duration_type get_neg_offset(const date_type& d) const { ymd_type ymd(d.year_month_day()); if (origDayOfMonth_ == 0) { origDayOfMonth_ = ymd.day; day_type endOfMonthDay(cal_type::end_of_month_day(ymd.year,ymd.month)); if (endOfMonthDay == ymd.day) { origDayOfMonth_ = -1; //force the value to the end of month } } typedef date_time::wrapping_int2
wrap_int2; typedef typename wrap_int2::int_type int_type; wrap_int2 wi(ymd.month); //calc the year wrap around, add() returns 0 or 1 if wrapped int_type year = wi.subtract(static_cast
(f_)); year = static_cast
(year + ymd.year); //calculate resulting year //find the last day for the new month day_type resultingEndOfMonthDay(cal_type::end_of_month_day(year, wi.as_int())); //original was the end of month -- force to last day of month if (origDayOfMonth_ == -1) { return date_type(year, wi.as_int(), resultingEndOfMonthDay) - d; } day_type dayOfMonth = origDayOfMonth_; if (dayOfMonth > resultingEndOfMonthDay) { dayOfMonth = resultingEndOfMonthDay; } return date_type(year, wi.as_int(), dayOfMonth) - d; } private: int f_; mutable short origDayOfMonth_; }; //! Functor to iterate a over weeks template
class week_functor { public: typedef typename date_type::duration_type duration_type; typedef typename date_type::calendar_type calendar_type; week_functor(int f) : f_(f) {} duration_type get_offset(const date_type& d) const { // why is 'd' a parameter??? // fix compiler warnings d.year(); return duration_type(f_*calendar_type::days_in_week()); } duration_type get_neg_offset(const date_type& d) const { // fix compiler warnings d.year(); return duration_type(-f_*calendar_type::days_in_week()); } private: int f_; }; //! Functor to iterate by a year adjusting for leap years template
class year_functor { public: //typedef typename date_type::year_type year_type; typedef typename date_type::duration_type duration_type; year_functor(int f) : _mf(f * 12) {} duration_type get_offset(const date_type& d) const { return _mf.get_offset(d); } duration_type get_neg_offset(const date_type& d) const { return _mf.get_neg_offset(d); } private: month_functor
_mf; }; } }//namespace date_time #endif
adjust_functors.hpp
Page URL
File URL
Prev 1/60
Next
Download
( 5 KB )
Note: The DriveHQ service banners will NOT be displayed if the file owner is a paid member.
Comments
Total ratings:
0
Average rating:
Not Rated
Would you like to comment?
Join DriveHQ
for a free account, or
Logon
if you are already a member.