Webylon 3.1 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
  • Download
Version: current
  • 3.2
  • 3.1

Packages

  • auth
  • Booking
  • cart
    • shipping
    • steppedcheckout
  • Catalog
  • cms
    • assets
    • batchaction
    • batchactions
    • bulkloading
    • comments
    • content
    • core
    • export
    • newsletter
    • publishers
    • reports
    • security
    • tasks
  • Dashboard
  • DataObjectManager
  • event
  • faq
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formatted
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • googlesitemaps
  • guestbook
  • installer
  • newsletter
  • None
  • photo
    • gallery
  • PHP
  • polls
  • recaptcha
  • sapphire
    • api
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • filesystem
    • formatters
    • forms
    • i18n
    • integration
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • tools
    • validation
    • view
    • widgets
  • seo
    • open
      • graph
  • sfDateTimePlugin
  • spamprotection
  • stealth
    • captha
  • subsites
  • userform
    • pagetypes
  • userforms
  • webylon
  • widgets

Classes

  • AdditionalMenuWidget_Item
  • AdvancedSliderHomepageWidget_Item
  • AssetManagerFolder
  • BannerWidget_Item
  • BaseObjectDecorator
  • BookingOrder
  • BookingPaymentMethod
  • BookingService
  • Boolean
  • ButtonsBlockHomepageWidget_Item
  • CarouselHomepageWidget_Item
  • CatalogRubricsHomepageWidget_CatalogDecorator
  • ClientEmailOrderNotification
  • ClientVKOrderNotification
  • ComponentSet
  • Currency
  • DatabaseAdmin
  • DataObject
  • DataObjectDecorator
  • DataObjectLog
  • DataObjectSet
  • DataObjectSet_Iterator
  • Date
  • DB
  • DBField
  • Decimal
  • DocumentItem
  • DocumentPage_File
  • Double
  • Enum
  • ErrorPageSubsite
  • FileDataObjectTrackingDecorator
  • FileImportDecorator
  • Float
  • ForeignKey
  • Hierarchy
  • HTMLText
  • HTMLVarchar
  • ImportLog_Item
  • Int
  • ManagerEmailOrderNotification
  • Material3D_File
  • MediawebPage_File
  • MediawebPage_Photo
  • MobileContentDecorator
  • Money
  • MultiEnum
  • MySQLDatabase
  • MySQLQuery
  • OrderDataObject
  • OrderHandlersDecorator
  • OrderItemVariationDecorator
  • OrderService
  • OrderServiceOrder
  • OrdersExportDecorator
  • PageIcon
  • PageWidgets
  • Payment
  • PaymentMethodShippingDecorator
  • PaymentOrderExtension
  • Percentage
  • PhotoAlbumItem
  • PhotoAlbumProductLinkDecorator
  • PhotoAlbumWidgetLinkDecorator
  • PhotoGalleryHomepageWidget_Item
  • PrimaryKey
  • Product3DDecorator
  • ProductCatalogCatalogLinkedDecorator
  • RatePeriod
  • RealtyImportLog
  • RealtyImportLog_Item
  • RedirectEntry
  • RoomOrder
  • RoomOrderPerson
  • RoomRate
  • RoomService
  • RoomServiceOrder
  • SberbankPaymentDecorator
  • SeoOpenGraphPageDecorator
  • ServiceOrder
  • ShippingMethodPaymentDecorator
  • ShopCountry
  • SimpleOrderCatalogDecorator
  • SimpleOrderProductDecorator
  • SiteConfigWidgets
  • SiteTreeDecorator
  • SiteTreeImportDecorator
  • SliderHomepageWidget_Item
  • SMSCOrderNotification
  • SMSOrderNotification
  • SortableDataObject
  • SQLMap
  • SQLMap_Iterator
  • SQLQuery
  • SS_Database
  • SS_Datetime
  • SS_Query
  • StringField
  • SubsiteDomain
  • Text
  • TextAnonsWidget_Item
  • Texture3D_File
  • Time
  • Varchar
  • Versioned
  • Versioned_Version
  • VideoCategory
  • VideoEntry
  • VKNotificationQueue
  • WebylonWidget_Item
  • YaMoneyPaymentDecorator
  • Year

Interfaces

  • CompositeDBField
  • CurrentPageIdentifier
  • DataObjectInterface
  1 <?php
  2 /**
  3  * Represents a date-time field.
  4  * The field currently supports New Zealand date format (DD/MM/YYYY),
  5  * or an ISO 8601 formatted date and time (Y-m-d H:i:s).
  6  * Alternatively you can set a timestamp that is evaluated through
  7  * PHP's built-in date() and strtotime() function according to your system locale.
  8  * 
  9  * For all computations involving the current date and time,
 10  * please use {@link SS_Datetime::now()} instead of PHP's built-in date() and time()
 11  * methods. This ensures that all time-based computations are testable with mock dates
 12  * through {@link SS_Datetime::set_mock_now()}.
 13  * 
 14  * @todo Add localization support, see http://open.silverstripe.com/ticket/2931
 15  * 
 16  * @package sapphire
 17  * @subpackage model
 18  */
 19 class SS_Datetime extends Date {
 20     
 21     function setValue($value) {
 22         // Default to NZ date format - strtotime expects a US date
 23         if(ereg('^([0-9]+)/([0-9]+)/([0-9]+)$', $value, $parts)) {
 24             $value = "$parts[2]/$parts[1]/$parts[3]";
 25         }
 26         
 27         if(is_numeric($value)) {
 28             $this->value = date('Y-m-d H:i:s', $value);
 29         } elseif(is_string($value)) {
 30             $this->value = date('Y-m-d H:i:s', strtotime($value));
 31         }
 32     }
 33 
 34     function Nice() {
 35         return date('d/m/Y g:ia', strtotime($this->value));
 36     }
 37     function Nice24() {
 38         return date('d/m/Y H:i', strtotime($this->value));
 39     }
 40     function Date() {
 41         return date('d/m/Y', strtotime($this->value));
 42     }
 43     function Time() {
 44         return date('g:ia', strtotime($this->value));
 45     }
 46     function Time24() {
 47         return date('H:i', strtotime($this->value));
 48     }
 49 
 50     function requireField() {
 51         $parts=Array('datatype'=>'datetime', 'arrayValue'=>$this->arrayValue);
 52         $values=Array('type'=>'SS_Datetime', 'parts'=>$parts);
 53         DB::requireField($this->tableName, $this->name, $values);
 54     }
 55     
 56     function URLDatetime() {
 57         return date('Y-m-d%20H:i:s', strtotime($this->value));
 58     }
 59     
 60     public function scaffoldFormField($title = null, $params = null) {
 61         return new DatetimeField($this->name, $title);
 62     }
 63     
 64     public function scaffoldSearchField($title = null) {
 65         return new TextField($this->name, $title);
 66     }
 67     
 68     /**
 69      * 
 70      */
 71     protected static $mock_now = null;
 72     
 73     /**
 74      * Returns either the current system date as determined
 75      * by date(), or a mocked date through {@link set_mock_now()}.
 76      * 
 77      * @return SS_Datetime
 78      */
 79     static function now() {
 80         if(self::$mock_now) {
 81             return self::$mock_now;
 82         } else {
 83             return DBField::create('SS_Datetime', date('Y-m-d H:i:s'));
 84         }
 85     }
 86     
 87     /**
 88      * Mock the system date temporarily, which is useful for time-based unit testing.
 89      * Use {@link clear_mock_now()} to revert to the current system date.
 90      * Caution: This sets a fixed date that doesn't increment with time.
 91      * 
 92      * @param SS_Datetime|string $datetime Either in object format, or as a SS_Datetime compatible string.
 93      */
 94     static function set_mock_now($datetime) {
 95         if($datetime instanceof SS_Datetime) {
 96             self::$mock_now = $datetime;
 97         } elseif(is_string($datetime)) {
 98             self::$mock_now = DBField::create('SS_Datetime', $datetime);
 99         } else {
100             throw new Exception('SS_Datetime::set_mock_now(): Wrong format: ' . $datetime);
101         }
102     }
103     
104     /**
105      * Clear any mocked date, which causes
106      * {@link Now()} to return the current system date.
107      */
108     static function clear_mock_now() {
109         self::$mock_now = null;
110     }
111 }
112 
113 ?>
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -
Webylon 3.1 API Docs API documentation generated by ApiGen 2.8.0