 
   opensAt
 
-getQueriedDueAt = ->
+getCurrentDueAt = (planId) ->
   {due_at} = Router.currentQuery() # attempt to read the due date from query params
-  TimeHelper.getMomentPreserveDate(due_at).format(TimeHelper.ISO_DATE_FORMAT) if due_at
+  if due_at?
+    TimeHelper.getMomentPreserveDate(due_at).format(TimeHelper.ISO_DATE_FORMAT)
+  else if TaskingStore.hasTasking(planId)
+    TaskingStore.getFirstDueDate(planId)
 
 getTaskPlanOpensAt = (planId) ->
   firstDueAt = _.first(TaskPlanStore.get(planId)?.tasking_plans)?.due_at


setPeriodDefaults = (courseId, planId, term) ->
  unless TaskingStore.hasTasking(planId)
    if TaskPlanStore.isNew(planId) and not TaskingStore.hasTasking(planId)
      due_date = getQueriedDueAt() or getTaskPlanOpensAt(planId)
      TaskingActions.create(planId, {open_date: getQueriedOpensAt(planId, term.start), due_date})
    else
      {tasking_plans} = TaskPlanStore.get(planId)
      TaskingActions.loadTaskings(planId, tasking_plans)

  TaskingActions.loadDefaults(courseId, courseDefaults, periods)


module.exports = (planId, courseId, term) ->
  courseTimezone = CourseStore.getTimezone(courseId)
  TaskingActions.loadTaskToCourse(planId, courseId)
  loadCourseDefaults(courseId)

  #set the periods defaults only after the timezone has been synced
  return setPeriodDefaults(courseId, planId, term)
