Time Entry

Supported by Redmine starting from version 1.1

Manager

All operations on the TimeEntry resource are provided by it’s manager. To get access to it you have to call redmine.time_entry where redmine is a configured redmine object. See the Configuration about how to configure redmine object.

Create methods

create

redminelib.managers.ResourceManager.create(**fields)

Creates new TimeEntry resource with given fields and saves it to the Redmine.

Parameters:
  • issue_id or project_id (int) – (required). The issue id or project id to log time on.
  • hours (int or float) – (required). The number of spent hours.
  • spent_on (string or date object) – (optional). The date the time was spent (current date if not set).
  • activity_id (int) – (optional). The id of the time activity. This parameter is required unless a default activity is defined in Redmine.
  • comments (string) – (optional). Short description for the entry (255 characters max).
Returns:

Resource object

>>> time_entry = redmine.time_entry.create(
...     issue_id=123,
...     spent_on=datetime.date(2014, 1, 14),
...     hours=3,
...     activity_id=10,
...     comments='hello'
... )
>>> time_entry
<redminelib.resources.TimeEntry #12345>

new

redminelib.managers.ResourceManager.new()

Creates new empty TimeEntry resource but saves it to the Redmine only when save() is called, also calls pre_create() and post_create() methods of the Resource object. Valid attributes are the same as for create() method above.bove.

Returns:Resource object
>>> time_entry = redmine.time_entry.new()
>>> time_entry.issue_id = 123
>>> time_entry.spent_on = datetime.date(2014, 1, 14)
>>> time_entry.hours = 3
>>> time_entry.activity_id = 10
>>> time_entry.comments = 'hello'
>>> time_entry.save()
True

Read methods

get

redminelib.managers.ResourceManager.get(resource_id)

Returns single TimeEntry resource from Redmine by it’s id.

Parameters:resource_id (int) – (required). Id of the time entry.
Returns:Resource object
>>> time_entry = redmine.time_entry.get(374)
>>> time_entry
<redminelib.resources.TimeEntry #374>

all

redminelib.managers.ResourceManager.all(**params)

Returns all TimeEntry resources from Redmine.

Parameters:
  • limit (int) – (optional). How much resources to return.
  • offset (int) – (optional). Starting from what resource to return the other resources.
Returns:

ResourceSet object

>>> time_entries = redmine.time_entry.all(offset=10, limit=100)
>>> time_entries
<redminelib.resultsets.ResourceSet object with TimeEntry resources>

filter

redminelib.managers.ResourceManager.filter(**filters)

Returns TimeEntry resources that match the given lookup parameters.

Parameters:
  • project_id (int or string) – (optional). Get time entries from the project with given id.
  • issue_id (int) – (optional). Get time entries from the issue with given id.
  • user_id (int) – (optional). Get time entries for the user with given id.
  • spent_on (string or date object) – (optional). Redmine >= 2.3.0 only. Date when time was spent.
  • from_date (string or date object) – (optional). Limit time entries from this date.
  • to_date (string or date object) – (optional). Limit time entries until this date.
  • hours (string) – (optional). Get only time entries that are =, >=, <= hours.
  • limit (int) – (optional). How much resources to return.
  • offset (int) – (optional). Starting from what resource to return the other resources.
Returns:

ResourceSet object

>>> time_entries = redmine.time_entry.filter(offset=10, limit=100, project_id='vacation', hours='>=8')
>>> time_entries
<redminelib.resultsets.ResourceSet object with TimeEntry resources>

Hint

You can also get time entries from an Issue, Project and User resource objects directly using time_entries relation:

>>> issue = redmine.issue.get(34213)
>>> issue.time_entries
<redminelib.resultsets.ResourceSet object with TimeEntry resources>

Update methods

update

redminelib.managers.ResourceManager.update(resource_id, **fields)

Updates values of given fields of a TimeEntry resource and saves them to the Redmine.

Parameters:
  • resource_id (int) – (required). Time entry id.
  • issue_id or project_id (int) – (optional). The issue id or project id to log time on.
  • hours (int) – (optional). The number of spent hours.
  • spent_on (string or date object) – (optional). The date the time was spent.
  • activity_id (int) – (optional). The id of the time activity.
  • comments (string) – (optional). Short description for the entry (255 characters max).
Returns:

True

>>> redmine.time_entry.update(
...     1,
...     issue_id=123,
...     spent_on=datetime.date(2014, 1, 14),
...     hours=3,
...     activity_id=10,
...     comments='hello'
... )
True

save

redminelib.resources.TimeEntry.save()

Saves the current state of a TimeEntry resource to the Redmine. Fields that can be changed are the same as for update() method above.

Returns:True
>>> time_entry = redmine.time_entry.get(1)
>>> time_entry.issue_id = 123
>>> time_entry.spent_on = datetime.date(2014, 1, 14)
>>> time_entry.hours = 3
>>> time_entry.activity_id = 10
>>> time_entry.comments = 'hello'
>>> time_entry.save()
True

Delete methods

delete

redminelib.managers.ResourceManager.delete(resource_id)

Deletes single TimeEntry resource from Redmine by it’s id.

Parameters:resource_id (int) – (required). Time entry id.
Returns:True
>>> redmine.time_entry.delete(1)
True
redminelib.resources.TimeEntry.delete()

Deletes current TimeEntry resource object from Redmine.

Returns:True
>>> entry = redmine.time_entry.get(1)
>>> entry.delete()
True

Export

New in version 2.0.0.

redminelib.resultsets.ResourceSet.export(fmt, savepath=None, filename=None)

Exports a resource set of TimeEntry resources in one of the following formats: atom, csv

Parameters:
  • fmt (string) – (required). Format to use for export.
  • savepath (string) – (optional). Path where to save the file.
  • filename (string) – (optional). Name that will be used for the file.
Returns:

String or Object

>>> entries = redmine.time_entry.all()
>>> entries.export('csv', savepath='/home/jsmith', filename='entries.csv')
'/home/jsmith/entries.csv'