Fieldcode Manual

Tip: You can use filters for better results

The fcdatetime module is the Fieldcode implemented alternative of the standard datetime module to add support for date and time types. Just like its official counterpart, the aim of the library is to provide support for manipulating dates and times.

Below are the types available through the fcdatetime module.

class fcdatetime.fcdate

A type representing an idealized date object with no timezone or offset information.
Attributes: year, month and day.

class fcdatetime.fctime

An idealized time, independent of any particular day, assuming that every day has exactly 24*60*60 seconds. (There is no notion of “leap seconds” here.) Instead of timezone information, this implementation provides offset information.
Attributes: hour, minute, second, millisecond, offsethour and offsetminute.

class fcdatetime.fcdatetime

A combination of a date and a time.
Attributes: year, month, day, hour, minute, second, millisecond, offsethour and offsetminute.

Objects of these types are immutable.

Subclass relationships:

				object
    fctime
    fcdate
        fcdatetime
			

A fcdate object represents an epoch date (year, month, and day) in the Gregorian calendar, starting from the year 1970.

January 1 of year 1970 is called epoch day number 1, January 2 of year 1970 is called epoch day number 2, and so on.

Constructor:

class fcdatetime.fcdate(year, month, day)

All arguments are required. Arguments must be numbers, in the following ranges:

  • 1970 <= year <= 999999999,
  • 1 <= month <= 12,
  • 1 <= day <= number of days in the given month and year.

    If an argument ouside those ranges is given, an Exception will be raised on runtime.

Other constructors, all class methods:

classmethod fcdate.today()

Return the current local date.

classmethod fcdate.fromformat(date_string, date_format)

Parses the string representation of a date into an fcdate object using the given format.

  • date_string is the string representation of any date or date and time.
  • date_format is a Java DateTimeFormatter pattern format matching the date_string.

    If the parsing is unsuccessful, None will be returned.

classmethod fcdate.fromepochday(epochday)

Creates an fcdate object representing the given epoch day.

classmethod fcdate.fromepochmillisecond(epochmillisecond)

Creates an fcdate object representing the epoch day truncated from the given epoch millisecond.

Class attributes:

This object does not have class attributes.

Instance attributes (read-only):

fcdate.year

Between 1970 and 999999999 inclusive.

fcdate.month

Between 1 and 12 inclusive.

fcdate.day

Between 1 and the number of days in the given month of the given year.

Supported operations:

OperationResult
fcdate2 = fcdate1 + numberfcdate2 will be number milliseconds truncated to days after fcdate1. (1)
fcdate2 = fcdate1 - numberfcdate2 will be number milliseconds truncated to days before fcdate1. (2)
fcdate1 < fcdate2fcdate1 is considered less than fcdate2 when fcdate1 precedes fcdate2 in time. (3)

Notes:

  1. fcdate2 is moved forward in time if number > 0, or backward if number < 0. Afterward fcdate2.epochmillisecond() – fcdate1.epochmillisecond() <= number.
  2. fcdate2 is moved backward in time if number > 0, or forward if number < 0. Afterward fcdate1.epochmillisecond() – fcdate2.epochmillisecond() <= number.
  3. In other words, fcdate1 < fcdate2 if and only if fcdate1.epochday() < fcdate2.epochday(). Date comparison raises TypeError if the other comparand isn’t also an fcdate object.

Instance Methods:

fcdate.epochday()

Return the epoch day represented by the date.

fcdate.epochmillisecond()

Return the epoch millisecond represented by the date at midnight.

fcdate.format(pattern)

Return a string representing the date in the given Java DateTimeFormatter pattern. For example, fcdate(2002, 12, 4).format(‘YYYY-MM-DD’) == ‘2002-12-04’.

fcdate.weekday()

Return the day of the week as a number, where Monday is 0 and Sunday is 6. For example, fcdate(2002, 12, 4).weekday() == 2, a Wednesday. See also isoweekday().

fcdate.isoweekday()

Return the day of the week as a number, where Monday is 1 and Sunday is 7. For example, fcdate(2002, 12, 4).weekday() == 3, a Wednesday. See also weekday().

Coming Soon!

A fctime object represents an offset time of day, independent of any particular day, and subject to adjustment via its offset hour and offset minute.

Constructor:

class fcdatetime.fctime(hour=0, minute=0, second=0, millisecond=0, offsethour=0, offsetminute=0)

All arguments are optional. Arguments must be numbers in the following ranges:

  • 0 <= hour < 24,
  • 0 <= minute < 60,
  • 0 <= second < 60,
  • 0 <= millisecond < 1000,
  • -18 <= offsethour <= 18,
  • 0 <= offsetminute < 60.

If an argument ouside those ranges is given, an Exception will be raised on runtime.

Other constructors, all class methods:

classmethod fctime.utcnow()

Return the current local time in UTC.

classmethod fctime.fromformat(time_string, time_format)

Parses the string representation of a time into an fctime object using the given format.

  • time_string is the string representation of any time or date and time.
  • time_format is a Java DateTimeFormatter pattern format matching the time_string.

If the parsing is unsuccessful, None will be returned.

classmethod fctime.utcfrommilliseconds(milliseconds)

Creates an fctime object from the given milliseconds in UTC.

Class attributes:

This object does not have class attributes.

Instance attributes (read-only):

fctime.hour

In range(24).

fctime.minute

In range(60).

fctime.second

In range(60).

fctime.millisecond

In range(1000).

fctime.offsethour

Between -18 and +18 inclusive.

fctime.offsetminute

In range(60).

OperationResult
fctime2 = fctime1 + number fctime2 will be number milliseconds after fctime1. (1)
fctime2 = fctime1 - number fctime2 will be number milliseconds before fctime1. (2)
fctime1 < fctime2 fctime1 is considered less than fctime2 when fctime1 precedes fctime2 in time. (3)

Instance methods:

fctime.asoffset(hour, minute=0)

Return the local time adjusted to the given offset. Arguments must be numbers in the following ranges:

  • -18 <= hour <= 18,
  • 0 <= minute < 60.

fctime.asutc()

Return the local time adjusted to UTC.

fctime.total_milliseconds()

Return the total number of milliseconds contained in the local time.

fctime.format(pattern)

Return a string representing the local time in the given Java DateTimeFormatter pattern. For example, fctime(12, 30, 0, 500, 1, 0).format(‘HH:mm:ss.SSSXXX’) == ’12:30:00.500+01:00′.

fctime.offset()

Return the offset of the local time in string format of ±HH:mm.

Coming Soon!

An fcdatetime object is a single object containing all the information from an fcdate object and an fctime object.

Lke an fcdate object, fcdatetime assumes the Gregorian calendar, starting from year 1970; like an fctime object, fcdatetime assumes there are exactly 3600*24 seconds in every day.

Constructor:

class fcdatetime.fcdatetime(year, month, day, hour=0, minute=0, second=0, millisecond=0, offsethour=0, offsetminute=0)

The year, month and day arguments are required. The remaining arguments are optional. Arguments must be numbers in the following ranges:

  • 1970 <= year <= 999999999,
  • 1 <= month <= 12,
  • 1 <= day <= number of days in the given month and year,
  • 0 <= hour < 24,
  • 0 <= minute < 60,
  • 0 <= second < 60,
  • 0 <= millisecond < 1000,
  • -18 <= offsethour <= 18,
  • 0 <= offsetminute < 60.

    If an argument ouside those ranges is given, an Exception will be raised on runtime.

Other constructors, all class methods:

classmethod fcdatetime.utcnow()

Return the current local date and time in UTC.

classmethod fcdatetime.today()

Return the current local date at midnight in UTC.

classmethod fcdatetime.combine(date, time)

Return a new fcdatetime object whose date components are equal to the given fcdate object’s, and whose time components are equal to the given fctime object’s.

For any fcdatetime object d, d == datetime.combine(d.date(), d.time()).

classmethod fcdatetime.fromformat(time_string, time_format)

Parses the string representation of a time into an fctime object using the given format.

  • time_string is the string representation of any time or date and time.
  • time_format is a Java DateTimeFormatter pattern format matching the time_string.

    If the parsing is unsuccessful, None will be returned.

classmethod fcdatetime.utcfromepochmillisecond(epochmillisecond)

Creates an fcdatetime object representing the given epoch millisecond in UTC.

Class attributes:

This object does not have class attributes.

Instance attributes (read-only):

fcdatetime.year

Between 1970 and 999999999 inclusive.

fcdatetime.month

Between 1 and 12 inclusive.

fcdatetime.day

Between 1 and the number of days in the given month of the given year.

fcdatetime.hour

In range(24).

fcdatetime.minute

In range(60).

fcdatetime.second

In range(60).

fcdatetime.millisecond

In range(1000).

fcdatetime.offsethour

Between -18 and +18 inclusive.

fcdatetime.offsetminute

In range(60).

Supported operations:

OperationResult
fcdatetime2 = fcdatetime1 + numberfcdatetime2 will be number milliseconds after fcdatetime1. (1)
fcdatetime2 = fcdatetime1 - numberfcdatetime2 will be number milliseconds before fcdatetime1. (2)
fcdatetme1 < fcdatetime2 fcdatetime1 is considered less than fcdatetime2 when fcdatetime1 precedes fcdatetime2 in time. (3)

Instance methods:

fcdatetime.date()

Return an fcdate object with same year, month and day.

fcdatetime.time()

Return an fctime object with same hour, minute, second, millisecond and offset.

fcdatetime.asoffset(hour, minute=0)

Return the offset date and time adjusted to the given offset.
Arguments must be numbers in the following ranges:

  • -18 <= hour <= 18,
  • 0 <= minute < 60.

fcdatetime.astimezone(tz)

Return the offset date and time adjusted to the given time zone ID. The tz argument must be a string which represents any of the supported time zone ID-s .

fcdatetime.asutc()

Return the offset date and time adjusted to UTC.

fcdatetime.epochday()

Return the epoch day represented by the date part of the offset date and time.

fcdatetime.epochmillisecond()

Return the epoch millisecond represented by the offset date and time.

fcdatetime.format(pattern)

Return a string representing the offset date and time in the given Java DateTimeFormatter pattern . For example, fcdatetime(2002, 12, 4, 12, 30, 0, 500, 1, 0).format(‘YYYY-MM-DD\’T\’HH:mm:ss.SSSXXX’) == ‘2002-12-04T12:30:00.500+01:00’.

fcdatetime.weekday()

Return the day of the week as a number, where Monday is 0 and Sunday is 6. For example, fcdatetime(2002, 12, 4).weekday() == 2, a Wednesday. See also isoweekday().

fcdatetime.isoweekday()

Return the day of the week as a number, where Monday is 1 and Sunday is 7. For example, fcdatetime(2002, 12, 4).weekday() == 3, a Wednesday. See also weekday().

fcdatetime.offset()

Return the offset of the offset date and time in string format of ±HH:mm.

Coming Soon!

Was this topic helpful?
0 out of 5 stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
5
How can we further improve this topic?
Please provide the reason for your vote. This will help us improve this topic.
Navigation