class DateTimeFieldFormatType
An enumeration-style class that defines constants for specifying date and time display formats.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/sharepoint/fields/datetime_field_format_type.py
1 - 8
simple
Purpose
This class serves as a namespace for constants that specify how date and time fields should be formatted when displayed. It provides two format options: DateOnly (value 0) for displaying only the date portion, and DateTime (value 1) for displaying both date and time components. This is typically used in UI components, reporting systems, or data formatting utilities where consistent date/time display formatting is required.
Source Code
class DateTimeFieldFormatType:
"""Specifies the format to use in displaying date and time fields."""
DateOnly = 0
"""Only the date is displayed."""
DateTime = 1
"""Both the date and the time are displayed."""
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
- | - |
Parameter Details
bases: This class does not have an __init__ method and is not meant to be instantiated. It serves as a container for class-level constants. The 'bases' mentioned in the docstring refers to the base classes in the class definition, which in this case is the default object base class.
Return Value
This class is not meant to be instantiated. It serves as a namespace for constants. Accessing DateTimeFieldFormatType.DateOnly returns the integer 0, and accessing DateTimeFieldFormatType.DateTime returns the integer 1. These integer values can be used as format type indicators in other parts of an application.
Class Interface
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
DateOnly |
int | Constant value (0) indicating that only the date portion should be displayed, excluding time information | class |
DateTime |
int | Constant value (1) indicating that both date and time portions should be displayed | class |
Usage Example
# Import the class (assuming it's in a module named datetime_format)
# from datetime_format import DateTimeFieldFormatType
# Use the constants to specify format types
format_type = DateTimeFieldFormatType.DateOnly
if format_type == DateTimeFieldFormatType.DateOnly:
print("Display date only")
# Output: Display date only
# Use in a function that formats dates
def format_datetime(dt, format_type):
if format_type == DateTimeFieldFormatType.DateOnly:
return dt.strftime('%Y-%m-%d')
elif format_type == DateTimeFieldFormatType.DateTime:
return dt.strftime('%Y-%m-%d %H:%M:%S')
return str(dt)
from datetime import datetime
now = datetime.now()
print(format_datetime(now, DateTimeFieldFormatType.DateOnly))
print(format_datetime(now, DateTimeFieldFormatType.DateTime))
Best Practices
- Do not instantiate this class - use it as a namespace for constants by accessing class attributes directly (e.g., DateTimeFieldFormatType.DateOnly)
- Use these constants instead of magic numbers (0, 1) throughout your codebase for better readability and maintainability
- Consider using Python's enum.Enum or enum.IntEnum for more robust enumeration behavior in production code
- These constants are immutable at the class level and should not be modified at runtime
- When comparing format types, use identity or equality checks with the class constants rather than comparing raw integer values
- This pattern is suitable for simple constant definitions but lacks the type safety and features of modern Python enums
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class DateTimeFormat 88.7% similar
-
class UrlFieldFormatType 68.2% similar
-
class FieldDateTime 61.9% similar
-
class CalendarType 59.6% similar
-
class FileSystemObjectType 54.4% similar